w3c-ccg / did-method-key

DID (Decentralized Identifier) did:key method for embedding keys in DID urls
https://w3c-ccg.github.io/did-method-key
Other
18 stars 12 forks source link

Use compressed EC keys #38

Closed clehner closed 2 years ago

clehner commented 3 years ago

Update index.html to match the test vectors updated in #36.

To find the "always start with" strings (ASCII prefixes for the key type), I used the following code to output the lowest and highest possible values.

Finding low and high values for string encoding ##### `package.json` ```json { "dependencies": { "bs58": "^4.0.1", "multicodec": "^3.0.1" } } ``` ##### `index.js` ```js const multicodec = require('multicodec') const bs58 = require('bs58') const p1 = multicodec.getVarintFromName('p256-pub') const p2 = multicodec.getVarintFromName('p384-pub') const p3 = multicodec.getVarintFromName('p521-pub') console.log('256') console.log('z' + bs58.encode(Buffer.concat([p1, Buffer.from([3]), Buffer.alloc(32)]))) console.log('z' + bs58.encode(Buffer.concat([p1, Buffer.from([4]), Buffer.alloc(32).fill(0xff)]))) console.log('384') console.log('z' + bs58.encode(Buffer.concat([p2, Buffer.from([3]), Buffer.alloc(48)]))) console.log('z' + bs58.encode(Buffer.concat([p2, Buffer.from([4]), Buffer.alloc(48).fill(0xff)]))) console.log('521') console.log('z' + bs58.encode(Buffer.concat([p3, Buffer.from([3]), Buffer.alloc(66)]))) console.log('z' + bs58.encode(Buffer.concat([p3, Buffer.from([4]), Buffer.alloc(66).fill(0xff)]))) ``` Output: ``` 256 zDnaehfHR8Q5U7ckmLQfuZ3eGEypooJ46zzjRQ1AR9asDvdnw zDnafJ7vA7yafhiEJUaEk1PzrdRRrJHLkVQscN754sRikxYHU 384 z82LkuunYkEaW6hnkwZoenagXUavk3RVEbwXBCFtxfxVSX4PXWp8RvfGuqMZi2Y1seKhBRh z82LmEh7HuG6tdmiDieQBvU7B7qxpWNyTbram9E8FDChZPJD2HP21Ejm968VqYDH1zW8zVU 521 z2J9gcGEGou6jrLk1mjqfd44NoDu2r2rktFi5Zpui3zDmFnaKeZwnjHwg1YwEaX9Y3gUpDohvPhW8zmpZBBV281UfXfSc1Wf z2J9gfheqNuXb3kUexfMSSsBXuyVnANQgS1MMdw8gYnMeffnRzXLLZbgjhFnvMn1W1fWitCE7BWUpXRAmnfDVc23eUAG1gHL ``` Longest common prefixes: `zDNa`, `z82Lm`, and `z2J9g`.
OR13 commented 3 years ago

@clehner you are a boss! thanks for this PR.

dmitrizagidulin commented 2 years ago

@clehner - this is awesome, thanks!