Creating a Sign In With Starkware (SIWStarkware) Message
This section describes how to generate Sign-In with Starkware (SIWStarkware) message
Creating SIWStarkware messages in JavaScript is straightforward when using the "@web3auth/sign-in-with-starkware"
npm library. To begin, create a
new project called sign-in-project.
mkdir sign-in-project && cd sign-in-project/
npm init --yes
npm install --save @web3auth/sign-in-with-starkware
mkdir src/
We can then write the following into ./src/index.js:
import { Header, Payload, SIWStarkware } from "@web3auth/sign-in-with-starkware";
const domain = "localhost";
const origin = "https://localhost/login";
function createStarkwareMessage(address, statement) {
const payload = new Payload();
payload.domain = domain;
payload.address = address;
payload.uri = origin;
payload.statement = statement;
payload.version = "1";
payload.chainId = 1;
payload.issuedAt = new Date().toISOString();
const header = new Header();
header.t = "eip191";
let message = new SIWStarkware({ header, payload });
return message.prepareMessage();
}
console.log(createStarkwareMessage("0x03f692906af79b6f65b0b9e7083e54145b0f7e00d942fb5ef219c3c3cecba8bd", "Hello world!"));
Now run the example:
node src/index.js
You should see output similar to the following message, with different values for the Nonce and Issued At fields:
localhost wants you to sign in with your Starkware account:
0x03f692906af79b6f65b0b9e7083e54145b0f7e00d942fb5ef219c3c3cecba8bd
Hello world!
URI: http://localhost:3000
Version: 1
Chain ID: 1
Nonce: oNCEHm5jzQU2WvuBB
Issued At: 2022-01-28T23:28:16.013Z
You might have to run npm i @babel/runtime
Learn about all the available fields in a SIWStarkware Message
The fields we are most interested in for this guide are the address and the statement. The address is the Starkware address which the user is signing in with, and the statement will describe to the user what action performed. Often, as in this example, we don't need to manipulate the message. We can immediately convert it into the textual representation that the user will sign.