Compare commits

...

6 Commits

Author SHA1 Message Date
Thunnini
c69788989d Change contract 2022-12-13 13:46:47 +09:00
Thunnini
ef68b49027 Change contract address 2022-12-12 18:57:59 +09:00
Thunnini
c900e86e3a Fix unknown problem 2022-12-12 18:57:49 +09:00
Thunnini
de2a90457e WIP: test execute 2022-12-12 17:50:52 +09:00
Thunnini
7ae09a0c11 Change some typings 2022-12-12 17:50:40 +09:00
Thunnini
1ea85324aa Use Buffer package instead of Buffer on nodejs 2022-12-12 16:12:04 +09:00
5 changed files with 184 additions and 44 deletions

View File

@ -5,10 +5,7 @@ import { useEffect, useState } from "react";
import Image from "next/image"; import Image from "next/image";
// Types // Types
import { import { IcnsVerificationResponse, TwitterAuthInfoResponse } from "../../types";
IcnsVerificationResponse,
TwitterAuthInfoResponse,
} from "../../types";
import { request } from "../../utils/url"; import { request } from "../../utils/url";
// Styles // Styles
@ -21,10 +18,17 @@ import { SkeletonChainList } from "../../components/skeleton";
import { PrimaryButton } from "../../components/primary-button"; import { PrimaryButton } from "../../components/primary-button";
import { AccountInfos } from "../../config"; import { AccountInfos } from "../../config";
import { import { TwitterProfile } from "../../components/twitter-profile";
TwitterProfile,
} from "../../components/twitter-profile";
import { ChainList } from "../../components/chain-list"; import { ChainList } from "../../components/chain-list";
import {
getKeplrFromWindow,
KeplrWallet,
makeCosmwasmExecMsg,
sendMsgs,
simulateMsgs,
} from "../../wallets";
import { TendermintTxTracer } from "@keplr-wallet/cosmos";
import { Buffer } from "buffer/";
export default function VerificationPage() { export default function VerificationPage() {
const [twitterAuthInfo, setTwitterAuthInfo] = const [twitterAuthInfo, setTwitterAuthInfo] =
@ -46,21 +50,147 @@ export default function VerificationPage() {
setTwitterAuthInfo(newTwitterAuthInfo); setTwitterAuthInfo(newTwitterAuthInfo);
await (async () => {
const keplr = await getKeplrFromWindow();
if (keplr) {
const wallet = new KeplrWallet(keplr);
const mainChainId = "osmo-test-4";
const chainIds = (await wallet.getChainInfosWithoutEndpoints()).map(
(c) => c.chainId,
);
await wallet.init(chainIds);
const key = await wallet.getKey(mainChainId);
const icnsVerificationList = ( const icnsVerificationList = (
await request<IcnsVerificationResponse>("/api/icns-verification", { await request<IcnsVerificationResponse>(
"/api/icns-verification",
{
method: "post", method: "post",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
claimer: "osmo1y5mm5nj5m8ttddt5ccspek6xgyyavehrkak7gq", claimer: key.bech32Address,
authToken: newTwitterAuthInfo.accessToken, authToken: newTwitterAuthInfo.accessToken,
}), }),
}) },
)
).verificationList; ).verificationList;
console.log(icnsVerificationList); console.log(icnsVerificationList);
const registerMsg = makeCosmwasmExecMsg(
key.bech32Address,
"osmo1u3sm9029430ca7xqz5afx4n0d42mgs2w97syex23g3vz2m673hxsv905sn",
{
claim: {
name: newTwitterAuthInfo.username,
verifying_msg:
icnsVerificationList[0].status === "fulfilled"
? icnsVerificationList[0].value.data.verifying_msg
: "",
verifications: icnsVerificationList.map((verification) => {
if (verification.status === "fulfilled") {
return {
public_key: verification.value.data.public_key,
signature: verification.value.data.signature,
};
}
}),
},
},
[
{
denom: "uosmo",
amount: "500000",
},
],
);
const test = await wallet.signICNSAdr36(
mainChainId,
"osmo1hnjg39mu9r9tygy6zpypd25rhmh9726jm369uh7z0r6gjkmnk5zs3tdtug",
key.bech32Address,
newTwitterAuthInfo.username,
chainIds,
);
const addressMsgs = test.map((adr36Info) => {
console.log(adr36Info);
return makeCosmwasmExecMsg(
key.bech32Address,
"osmo1hnjg39mu9r9tygy6zpypd25rhmh9726jm369uh7z0r6gjkmnk5zs3tdtug",
{
set_record: {
name: newTwitterAuthInfo.username,
bech32_prefix: adr36Info.bech32Prefix,
adr36_info: {
signer_bech32_address: adr36Info.bech32Address,
address_hash: adr36Info.addressHash,
pub_key: Buffer.from(adr36Info.pubKey).toString("base64"),
signature: Buffer.from(adr36Info.signature).toString(
"base64",
),
signature_salt: adr36Info.signatureSalt.toString(),
},
},
},
[],
);
});
const aminoMsgs = [registerMsg.amino];
const protoMsgs = [registerMsg.proto];
for (const addressMsg of addressMsgs) {
aminoMsgs.push(addressMsg.amino);
protoMsgs.push(addressMsg.proto);
}
const chainInfo = {
chainId: mainChainId,
rest: "https://lcd.testnet.osmosis.zone",
};
const simulated = await simulateMsgs(
chainInfo,
key.bech32Address,
{
proto: protoMsgs,
},
{
amount: [],
},
);
const txHash = await sendMsgs(
wallet,
chainInfo,
key.bech32Address,
{
amino: aminoMsgs,
proto: protoMsgs,
},
{
amount: [],
gas: Math.floor(simulated.gasUsed * 1.5).toString(),
},
);
const txTracer = new TendermintTxTracer(
"https://rpc.testnet.osmosis.zone",
"/websocket",
);
const result = await txTracer.traceTx(txHash);
console.log(result);
}
})();
setIsLoading(false); setIsLoading(false);
} }
}; };

View File

@ -21,8 +21,12 @@ export interface IcnsVerificationResponse {
value: { value: {
errors: Error[]; errors: Error[];
data: { data: {
// JSON string
verifying_msg: string; verifying_msg: string;
signature: number[]; // Base64 encoded
public_key: string;
// Base64 encoded
signature: string;
algorithm: string; algorithm: string;
}; };
}; };

View File

@ -1,5 +1,7 @@
export function base64URLEncode(str: Buffer) { import { Buffer } from "buffer/";
return str
export function base64URLEncode(str: Uint8Array) {
return Buffer.from(str)
.toString("base64") .toString("base64")
.replace(/\+/g, "-") .replace(/\+/g, "-")
.replace(/\//g, "_") .replace(/\//g, "_")

View File

@ -41,7 +41,7 @@ export class KeplrWallet implements Wallet {
constructor(public readonly keplr: Keplr) {} constructor(public readonly keplr: Keplr) {}
broadcastTxSync(chainId: string, tx: Uint8Array): Promise<Uint8Array> { broadcastTxSync(chainId: string, tx: Uint8Array): Promise<Uint8Array> {
return this.keplr.sendTx(chainId, tx, BroadcastMode.Sync); return this.keplr.sendTx(chainId, tx, "sync" as BroadcastMode);
} }
getChainInfosWithoutEndpoints(): Promise< getChainInfosWithoutEndpoints(): Promise<
@ -54,7 +54,7 @@ export class KeplrWallet implements Wallet {
getKey(chainId: string): Promise<{ getKey(chainId: string): Promise<{
readonly name: string; readonly name: string;
readonly pubKey: Uint8Array; readonly pubKey: Uint8Array;
readonly address: Uint8Array; readonly bech32Address: string;
}> { }> {
return this.keplr.getKey(chainId); return this.keplr.getKey(chainId);
} }
@ -77,7 +77,8 @@ export class KeplrWallet implements Wallet {
owner: string, owner: string,
username: string, username: string,
addressChainIds: string[], addressChainIds: string[],
): Promise<{ ): Promise<
{
chainId: string; chainId: string;
bech32Prefix: string; bech32Prefix: string;
bech32Address: string; bech32Address: string;
@ -85,7 +86,8 @@ export class KeplrWallet implements Wallet {
pubKey: Uint8Array; pubKey: Uint8Array;
signatureSalt: number; signatureSalt: number;
signature: Uint8Array; signature: Uint8Array;
}> { }[]
> {
// TODO: Update @keplr-wallet/types // TODO: Update @keplr-wallet/types
return (this.keplr as any).signICNSAdr36( return (this.keplr as any).signICNSAdr36(
chainId, chainId,

View File

@ -10,7 +10,7 @@ export interface Wallet {
getKey(chainId: string): Promise<{ getKey(chainId: string): Promise<{
readonly name: string; readonly name: string;
readonly pubKey: Uint8Array; readonly pubKey: Uint8Array;
readonly address: Uint8Array; readonly bech32Address: string;
}>; }>;
signAmino( signAmino(
chainId: string, chainId: string,
@ -25,7 +25,8 @@ export interface Wallet {
owner: string, owner: string,
username: string, username: string,
addressChainIds: string[], addressChainIds: string[],
): Promise<{ ): Promise<
{
chainId: string; chainId: string;
bech32Prefix: string; bech32Prefix: string;
bech32Address: string; bech32Address: string;
@ -33,5 +34,6 @@ export interface Wallet {
pubKey: Uint8Array; pubKey: Uint8Array;
signatureSalt: number; signatureSalt: number;
signature: Uint8Array; signature: Uint8Array;
}>; }[]
>;
} }