Skip to content

Commit

Permalink
Use single quotes instead of double quotes (#11)
Browse files Browse the repository at this point in the history
* Use single quotes instead of double quotes

Double quotes are not parseable by siwe-parser per the ABNF grammar they specify.

* Add valid test case with SIWE message as string

This test makes sure the SIWE message complies with the ABNF grammar specified in siwe-parser lib.

* Cleanup

* Add back ts-ignore
  • Loading branch information
hwrdtm authored May 8, 2023
1 parent f690f01 commit f7a0d70
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
7 changes: 2 additions & 5 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,14 @@ describe('Recap Handling', () => {
for (const { message, recap } of Object.values(valid).map(
// @ts-ignore
({ message, recap: { att, prf } }) => ({
// @ts-ignore
message: new SiweMessage(message),
// @ts-ignore
recap: { att, prf: prf.map(CID.decode) },
})
)) {
let decoded;
// @ts-ignore
let decoded: Recap;
expect(() => (decoded = Recap.extract_and_verify(message))).not.toThrow();
// @ts-ignore
expect(decoded.attenuations).toEqual(recap.att);
expect(decoded!.attenuations).toEqual(recap.att);
// @ts-ignore
let proofs = recap.prf.map(CID.decode);
// @ts-ignore
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ export class Recap {
}, {} as { [key: string]: Array<string> });

for (const [namespace, names] of Object.entries(resourceAbilities)) {
statement += `(${section}) "${namespace}": ${names
.map(n => '"' + n + '"')
.join(', ')} for "${resource}". `;
statement += `(${section}) '${namespace}': ${names
.map(n => `'${n}'`)
.join(', ')} for '${resource}'. `;
section += 1;
}
}
Expand Down
38 changes: 34 additions & 4 deletions test/valid.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
{
"withCapsMessageString": {
"message": "example.com wants you to sign in with your Ethereum account:\n0x0000000000000000000000000000000000000000\n\nI further authorize the stated URI to perform the following actions on my behalf: (1) 'kv': 'get', 'list', 'metadata' for 'kepler:ens:example.eth://default/kv'. (2) 'kv': 'delete', 'get', 'list', 'metadata', 'put' for 'kepler:ens:example.eth://default/kv/dapp-space'. (3) 'kv': 'delete', 'get', 'list', 'metadata', 'put' for 'kepler:ens:example.eth://default/kv/public'. (4) 'credential': 'present' for 'urn:credential:type:type1'.\n\nURI: did:key:example\nVersion: 1\nChain ID: 1\nNonce: mynonce1\nIssued At: 2022-06-21T12:00:00.000Z\nResources:\n- urn:recap:eyJhdHQiOnsia2VwbGVyOmVuczpleGFtcGxlLmV0aDovL2RlZmF1bHQva3YiOnsia3YvZ2V0Ijpbe31dLCJrdi9saXN0Ijpbe31dLCJrdi9tZXRhZGF0YSI6W3t9XX0sImtlcGxlcjplbnM6ZXhhbXBsZS5ldGg6Ly9kZWZhdWx0L2t2L2RhcHAtc3BhY2UiOnsia3YvZGVsZXRlIjpbe31dLCJrdi9nZXQiOlt7fV0sImt2L2xpc3QiOlt7fV0sImt2L21ldGFkYXRhIjpbe31dLCJrdi9wdXQiOlt7fV19LCJrZXBsZXI6ZW5zOmV4YW1wbGUuZXRoOi8vZGVmYXVsdC9rdi9wdWJsaWMiOnsia3YvZGVsZXRlIjpbe31dLCJrdi9nZXQiOlt7fV0sImt2L2xpc3QiOlt7fV0sImt2L21ldGFkYXRhIjpbe31dLCJrdi9wdXQiOlt7fV19LCJ1cm46Y3JlZGVudGlhbDp0eXBlOnR5cGUxIjp7ImNyZWRlbnRpYWwvcHJlc2VudCI6W3t9XX19LCJwcmYiOltdfQ",
"recap": {
"att": {
"kepler:ens:example.eth://default/kv": {
"kv/get": [{}],
"kv/list": [{}],
"kv/metadata": [{}]
},
"kepler:ens:example.eth://default/kv/dapp-space": {
"kv/delete": [{}],
"kv/get": [{}],
"kv/list": [{}],
"kv/metadata": [{}],
"kv/put": [{}]
},
"kepler:ens:example.eth://default/kv/public": {
"kv/delete": [{}],
"kv/get": [{}],
"kv/list": [{}],
"kv/metadata": [{}],
"kv/put": [{}]
},
"urn:credential:type:type1": {
"credential/present": [{}]
}
},
"prf": []
}
},
"withCaps": {
"message": {
"domain": "example.com",
"address": "0x0000000000000000000000000000000000000000",
"statement": "I further authorize the stated URI to perform the following actions on my behalf: (1) \"kv\": \"get\", \"list\", \"metadata\" for \"kepler:ens:example.eth://default/kv\". (2) \"kv\": \"delete\", \"get\", \"list\", \"metadata\", \"put\" for \"kepler:ens:example.eth://default/kv/dapp-space\". (3) \"kv\": \"delete\", \"get\", \"list\", \"metadata\", \"put\" for \"kepler:ens:example.eth://default/kv/public\". (4) \"credential\": \"present\" for \"urn:credential:type:type1\".",
"statement": "I further authorize the stated URI to perform the following actions on my behalf: (1) 'kv': 'get', 'list', 'metadata' for 'kepler:ens:example.eth://default/kv'. (2) 'kv': 'delete', 'get', 'list', 'metadata', 'put' for 'kepler:ens:example.eth://default/kv/dapp-space'. (3) 'kv': 'delete', 'get', 'list', 'metadata', 'put' for 'kepler:ens:example.eth://default/kv/public'. (4) 'credential': 'present' for 'urn:credential:type:type1'.",
"uri": "did:key:example",
"version": "1",
"chainId": "1",
"chainId": 1,
"nonce": "mynonce1",
"issuedAt": "2022-06-21T12:00:00.000Z",
"resources": [
Expand Down Expand Up @@ -45,10 +75,10 @@
"message": {
"domain": "example.com",
"address": "0x0000000000000000000000000000000000000000",
"statement": "Some custom statement. I further authorize the stated URI to perform the following actions on my behalf: (1) \"credential\": \"present\" for \"credential:*\".",
"statement": "Some custom statement. I further authorize the stated URI to perform the following actions on my behalf: (1) 'credential': 'present' for 'credential:*'.",
"uri": "did:key:example",
"version": "1",
"chainId": "1",
"chainId": 1,
"nonce": "mynonce1",
"issuedAt": "2022-06-21T12:00:00.000Z",
"resources": [
Expand Down

0 comments on commit f7a0d70

Please sign in to comment.