Skip to content

Commit bc2a264

Browse files
all tests passing
1 parent ef08dd9 commit bc2a264

File tree

3 files changed

+56
-179
lines changed

3 files changed

+56
-179
lines changed

package-lock.json

Lines changed: 14 additions & 157 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"dependencies": {
2828
"@web3auth/sign-in-with-ethereum": "^2.0.0",
2929
"@web3auth/sign-in-with-solana": "^2.0.0",
30-
"@web3auth/sign-in-with-starkware": "^1.0.0"
30+
"@web3auth/sign-in-with-starkware": "^2.0.0"
3131
},
3232
"devDependencies": {
3333
"bs58": "^5.0.0",

test/client.spec.ts

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ErrorTypes as ErrorTypesStarkware } from "@web3auth/sign-in-with-starkw
88
import assert from "assert";
99
import base58 from "bs58";
1010
import { Wallet } from "ethers";
11-
import { ec } from "starknet";
11+
import { ec, hash, stark, typedData } from "starknet";
1212

1313
import { Signature, SIWWeb3 } from "../src/index";
1414
import parsingPositiveEthereum from "./parsing_positive_ethereum.json";
@@ -89,7 +89,7 @@ describe(`Message Validation`, function () {
8989
it(`Validates message successfully - starkware: ${test}`, async function () {
9090
const { payload, signature, network, header } = value;
9191
const msg = new SIWWeb3({ payload, network, header });
92-
const starkKeyPair = ec.getKeyPair(payload.address.slice(2));
92+
const starkKeyPair = ec.getKeyPair(payload.address);
9393
const verify = await msg.verify(payload, signature, starkKeyPair);
9494
assert.equal(verify.success, true);
9595
});
@@ -128,7 +128,8 @@ describe(`Message Validation`, function () {
128128
try {
129129
const { payload, signature, network, header } = value;
130130
const msg = new SIWWeb3({ payload, network, header });
131-
const error = await msg.verify(payload, signature);
131+
const kp = ec.getKeyPair(payload.address);
132+
const error = await msg.verify(payload, signature, kp);
132133
assert(Object.values(ErrorTypesStarkware).includes(error.error.type));
133134
} catch (error) {
134135
// this is for time error
@@ -174,21 +175,40 @@ describe(`Round Trip Solana`, function () {
174175
});
175176
});
176177

177-
// describe(`Round Trip Starkware`, function () {
178-
// const rbytes = nacl.randomBytes(32);
179-
// const keypair = nacl.sign.keyPair.fromSeed(rbytes);
180-
// Object.entries(parsingPositiveSolana).forEach(([test, value]) => {
181-
// it(`Generates a Successfully Verifying message: ${test}`, async function () {
182-
// const { payload } = value.fields;
183-
// payload.address = base58.encode(keypair.publicKey);
184-
// const msg = new SIWWeb3({ payload });
185-
// const encodedMessage = new TextEncoder().encode(msg.prepareMessage());
186-
// const signatureEncoded = base58.encode(nacl.sign.detached(encodedMessage, keypair.secretKey));
187-
// const signature = new Signature();
188-
// signature.s = signatureEncoded;
189-
// signature.t = "sip99";
190-
// const { success } = await msg.verify(payload, signature);
191-
// assert.equal(success, true);
192-
// });
193-
// });
194-
// });
178+
describe(`Round Trip Starkware`, function () {
179+
const privateKey = stark.randomAddress();
180+
const starkKeyPair = ec.getKeyPair(privateKey);
181+
const fullPublicKey = ec.getStarkKey(starkKeyPair);
182+
Object.entries(parsingPositiveStarkware).forEach(([test, el]) => {
183+
it(`Generates a Successfully Verifying message: ${test}`, async function () {
184+
const { payload } = el.fields;
185+
payload.address = fullPublicKey;
186+
const msg = new SIWWeb3({ payload });
187+
const signature = new Signature();
188+
const message = hash.starknetKeccak(msg.prepareMessage()).toString("hex").substring(0, 31);
189+
const typedMessage: typedData.TypedData = {
190+
domain: {
191+
name: "Example DApp",
192+
chainId: payload.chainId,
193+
version: "0.0.1",
194+
},
195+
types: {
196+
StarkNetDomain: [
197+
{ name: "name", type: "felt" },
198+
{ name: "chainId", type: "felt" },
199+
{ name: "version", type: "felt" },
200+
],
201+
Message: [{ name: "message", type: "felt" }],
202+
},
203+
primaryType: "Message",
204+
message: {
205+
message,
206+
},
207+
};
208+
signature.s = ec.sign(starkKeyPair, typedData.getMessageHash(typedMessage, payload.address));
209+
signature.t = "eip191";
210+
const success = await msg.verify(payload, signature, starkKeyPair);
211+
assert.ok(success);
212+
});
213+
});
214+
});

0 commit comments

Comments
 (0)