Skip to content

Commit

Permalink
Update backend.md (#2402)
Browse files Browse the repository at this point in the history
- Add `Payload` class and `payloadSchema` object for clarification;
- Add a better explanation of the type for `payloadSchema.callbackUrl` and why the payloadSchema needs a `tag` prop.
  • Loading branch information
wpdas authored Jan 2, 2025
1 parent ba9c841 commit 704e759
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/2.build/4.web3-apps/backend/backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,29 @@ Once the user has signed the challenge, the wallet will call the `callbackUrl` w
const naj = require('near-api-js')
const js_sha256 = require("js-sha256")

class Payload {
constructor({ message, nonce, recipient, callbackUrl }) {
// The tag's value is a hardcoded value as per
// defined in the NEP [NEP413](https://github.com/near/NEPs/blob/master/neps/nep-0413.md)
this.tag = 2147484061;
this.message = message;
this.nonce = nonce;
this.recipient = recipient;
if (callbackUrl) { this.callbackUrl = callbackUrl }
}
}

const payloadSchema = {
struct: {
tag: "u32",
message: "string",
nonce: { array: { type: "u8", len: 32 } },
recipient: "string",
// Must be of type { option: "string" }
callbackUrl: { option: "string" },
},
};

export async function authenticate({ accountId, publicKey, signature }) {
// A user is correctly authenticated if:
// - The key used to sign belongs to the user and is a Full Access Key
Expand Down

0 comments on commit 704e759

Please sign in to comment.