dag_signMessage
Name
Type
Description
/**
* A base64 encoded string
* */
type Base64 = string;/**
* A JSON encoded string
* */
type JSONEncoded = string;Last updated
Was this helpful?
/**
* A base64 encoded string
* */
type Base64 = string;/**
* A JSON encoded string
* */
type JSONEncoded = string;Last updated
Was this helpful?
Was this helpful?
type JSONScalarValue = null | string | number | boolean;type SignatureRequest = {
content: string;
metadata: Record<string, JSONScalarValue>;
};// Build the signature request
const signatureRequest: SignatureRequest = {
content: "Sign this message to confirm your address",
metadata: {
user: "3feb69d6-d3f0-4812-9c93-384bee08afe8",
},
};
// Encode the signature request - Base64 < JSON < Request
const signatureRequestEncoded = window.btoa(JSON.stringify(signatureRequest));
await provider.request({
method: "dag_signMessage",
params: ["DAG88C9WDSKH451sisyEP3hAkgCKn5DN72fuwjfX", signatureRequestEncoded],
});
// "3045022100b35798008516373fcc6eef75fe8e322ce8fe0dccc4802b052f3ddc7c6b5dc2900220154cac1e4f3e7d9a64f4ed9d2a518221b273fe782f037a5842725054f1c62280"// Build the same signature request
const signatureRequest: SignatureRequest = {
content: "Sign this message to confirm your address",
metadata: {
user: "3feb69d6-d3f0-4812-9c93-384bee08afe8",
},
};
// get the public key
const publicKey = await provider.request({
method: "dag_getPublicKey",
params: [
"DAG88C9WDSKH451sisyEP3hAkgCKn5DN72fuwjfX", // Your DAG address
],
});
// same request used in dag_signMessage
const signatureRequestEncoded = window.btoa(JSON.stringify(signatureRequest));
// hash returned by dag_signMessage in the pevious example
const signature =
"3045022100b35798008516373fcc6eef75fe8e322ce8fe0dccc4802b052f3ddc7c6b5dc2900220154cac1e4f3e7d9a64f4ed9d2a518221b273fe782f037a5842725054f1c62280";
const message = `\u0019Constellation Signed Message:\n${signatureRequestEncoded.length}\n${signatureRequestEncoded}`;
const result = await dag4.keyStore.verify(publicKey, message, signature);
// true -> verification succeeded
// false -> verification failed