icns-frontend/messages/icns.ts

73 lines
2.0 KiB
TypeScript
Raw Normal View History

2022-12-15 10:06:44 +00:00
import { CosmwasmExecuteMessageResult } from "../types";
2022-12-15 06:02:50 +00:00
import { makeCosmwasmExecMsg } from "../wallets";
2022-12-15 10:06:44 +00:00
import { REGISTRAR_ADDRESS, RESOLVER_ADDRESS } from "../constants/icns";
2022-12-15 06:02:50 +00:00
import { ContractFee } from "../constants/wallet";
2022-12-14 11:36:08 +00:00
2022-12-15 06:02:50 +00:00
export const makeClaimMessage = (
senderAddress: string,
twitterUserName: string,
verificationList: any[],
2022-12-15 15:43:18 +00:00
referral?: string,
2022-12-15 06:02:50 +00:00
): CosmwasmExecuteMessageResult => {
2022-12-16 16:25:10 +00:00
verificationList = verificationList.filter((verification) => {
if (verification.status !== "fulfilled") {
console.log("verification", verification);
}
return verification.status === "fulfilled";
});
if (verificationList.length === 0) {
throw new Error("Verifications rejected all");
}
2022-12-15 06:02:50 +00:00
return makeCosmwasmExecMsg(
senderAddress,
REGISTRAR_ADDRESS,
{
claim: {
name: twitterUserName,
verifying_msg:
verificationList[0].status === "fulfilled"
? verificationList[0].value.data.verifying_msg
: "",
verifications: verificationList.map((verification) => {
if (verification.status === "fulfilled") {
return {
public_key: verification.value.data.public_key,
signature: verification.value.data.signature,
};
}
}),
2022-12-15 15:43:18 +00:00
referral,
2022-12-15 06:02:50 +00:00
},
},
[ContractFee],
);
};
export const makeSetRecordMessage = (
senderAddress: string,
twitterUserName: string,
adr36Info: any,
): CosmwasmExecuteMessageResult => {
return makeCosmwasmExecMsg(
senderAddress,
RESOLVER_ADDRESS,
{
set_record: {
name: twitterUserName,
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(),
},
},
},
[],
);
};