Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bshambaugh
Created October 21, 2022 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bshambaugh/59b62241aac35bfad4b75651589a156b to your computer and use it in GitHub Desktop.
Save bshambaugh/59b62241aac35bfad4b75651589a156b to your computer and use it in GitHub Desktop.
Error with js-did for P256 Remote signer
I am trying to find an error in my code* which appears to occur around:
const auth = await didObject.authenticate()
* [https://github.com/bshambaugh/BlinkyProject/blob/remoteSigner/testJWTremoteSigner/src/P256Provider_class.ts#L58](https://github.com/bshambaugh/BlinkyProject/blob/remoteSigner/testJWTremoteSigner/src/P256Provider_class.ts#L58)
**calls:**
const sign = async (
payload: Record<string, any> | string,
stream,
did: string,
protectedHeader: Record<string, any> = {}
) => {
const kid = `${did}#${did.split(':')[2]}`
const signer = remoteP256Signer(stream) // see remoteP256Signer.ts // const signer = EdDSASigner(secretKey)
const header = toStableObject(Object.assign(protectedHeader, { kid, alg: 'ES256' })) /// see https://datatracker.ietf.org/doc/html/rfc7518
return createJWS(typeof payload === 'string' ? payload : toStableObject(payload), signer, header)
}
**which produces the error:**
/home/ubuntu/Downloads/node_modules/dids/lib/did.js:175
throw new Error(`Failed to resolve ${didUrl}: ${error}${maybeMessage}`);
^
Error: Failed to resolve did:key:zDnaezUFn4zmNoNeZvBEdVyCv6MVL69X8NRD8YavTCJWGuXM7#zDnaezUFn4zmNoNeZvBEdVyCv6MVL69X8NRD8YavTCJWGuXM7: invalidDid, TypeError: Cannot read properties of undefined (reading 'keyToDidDoc')
at DID.<anonymous> (/home/ubuntu/Downloads/node_modules/dids/lib/did.js:175:23)
at Generator.next (<anonymous>)
at fulfilled (/home/ubuntu/Downloads/node_modules/dids/lib/did.js:5:58)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
**The constructor produces no error:**
const didObject = new DID({ provider , resolver: getResolver() })
so *const auth = await didObject.authenticate()* must create the error:
changing the kid changes the error message:
/home/ubuntu/Downloads/node_modules/dids/lib/did.js:175
throw new Error(`Failed to resolve ${didUrl}: ${error}${maybeMessage}`);
^
Error: Failed to resolve did:key:zDnaezUFn4zmNoNeZvBEdVyCv6MVL69X8NRD8YavTCJWGuXM7: invalidDid, TypeError: Cannot read properties of undefined (reading 'keyToDidDoc')
at DID.<anonymous> (/home/ubuntu/Downloads/node_modules/dids/lib/did.js:175:23)
at Generator.next (<anonymous>)
at fulfilled (/home/ubuntu/Downloads/node_modules/dids/lib/did.js:5:58)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
I am not sure where 'keyToDidDoc' comes from in js-did. The error references this code:
https://github.com/ceramicnetwork/js-did/blob/main/packages/dids/src/did.ts#L472-L486
@bshambaugh
Copy link
Author

scr-1666365097s

@bshambaugh
Copy link
Author

scr-1666364608s

@bshambaugh
Copy link
Author

scr-1666361856s

@bshambaugh
Copy link
Author

Also, originally I thought the did, and aud had to have specific names in JWTs, but apparently not:
decentralized-identity/did-jwt#252

@bshambaugh
Copy link
Author

bshambaugh commented Oct 26, 2022

https://github.com/bshambaugh/BlinkyProject/blob/remoteSigner/testJWTremoteSigner/src/P256Provider_class.ts#L58 is what produces the error is what is running on Node.js in architecture like:
DSC_0082s

@bshambaugh
Copy link
Author

bshambaugh commented Oct 26, 2022

https://github.com/bshambaugh/BlinkyProject/blob/remoteSigner/edgeDevices/ESP32-testing/src/main.cpp#L279-L284 is the code that is triggered for a cryptographic signature by RPC over websockets by the P256Provider_class.js code running on Node.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment