@polkadot/types/types#SignerPayloadRaw TypeScript Examples
The following examples show how to use
@polkadot/types/types#SignerPayloadRaw.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: methods.ts From metamask-snap-polkadot with Apache License 2.0 | 6 votes |
async function sign(
this: MetamaskPolkadotSnap,
method: "signPayloadJSON" | "signPayloadRaw",
payload: SignerPayloadJSON | SignerPayloadRaw
): Promise<{signature: string}> {
return (
await sendSnapMethod({
method,
params: {
payload
}
} as SignPayloadJSONRequest | SignPayloadRawRequest,
this.snapId
)
) as {signature: string};
}
Example #2
Source File: snap.ts From metamask-snap-polkadot with Apache License 2.0 | 6 votes |
public signer: InjectedSigner = {
signPayload: async (payload: SignerPayloadJSON): Promise<SignerResult> => {
const signature = await signPayloadJSON.bind(this)(payload);
const id = this.requestCounter;
this.requestCounter += 1;
return {id, signature};
},
signRaw: async (raw: SignerPayloadRaw): Promise<SignerResult> => {
const signature = await signPayloadRaw.bind(this)(raw);
const id = this.requestCounter;
this.requestCounter += 1;
return {id, signature};
},
update: () => null
};
Example #3
Source File: sign.ts From metamask-snap-polkadot with Apache License 2.0 | 6 votes |
export async function signPayloadRaw(
wallet: Wallet, api: ApiPromise, payload: SignerPayloadRaw
): Promise<{ signature: string }|void> {
// ask for confirmation
const confirmation = await showConfirmationDialog(
wallet,
`Do you want to sign following message: \n "${payload.data}" \n with account ${payload.address}`
);
// return seed if user confirmed action
if (confirmation) {
const keyPair = await getKeyPair(wallet);
const signedBytes = keyPair.sign(hexToU8a(payload.data));
return {
signature: u8aToHex(signedBytes)
};
}
}
Example #4
Source File: SingleAccountSigner.ts From interbtc-api with Apache License 2.0 | 6 votes |
public async signRaw ({ address, data }: SignerPayloadRaw): Promise<SignerResult> {
if (address !== this.#keyringPair.address) {
throw new Error("does not have the keyringPair");
}
return new Promise((resolve): void => {
setTimeout((): void => {
const signature = u8aToHex(this.#keyringPair.sign(hexToU8a(data)));
resolve({
id: ++id,
signature
});
}, this.#signDelay);
});
}
Example #5
Source File: methods.ts From metamask-snap-polkadot with Apache License 2.0 | 5 votes |
export async function signPayloadRaw(this: MetamaskPolkadotSnap, payload: SignerPayloadRaw): Promise<string> {
return (await sign.bind(this)("signPayloadRaw", payload)).signature;
}