-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: address #63; add padding to buffer for keys
- Loading branch information
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
packages/secp256k1/src/__tests__/31-byte-private-keys.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
import * as keyUtils from '../keyUtils'; | ||
|
||
// Originally reported in: | ||
// https://github.com/transmute-industries/did-key.js/issues/63 | ||
it('private keys MUST always be 32 bytes', async () => { | ||
// this JWK generatetes 31 byte length private keys | ||
const example = { | ||
"kty": "EC", | ||
"crv": "secp256k1", | ||
"d": "H8IPdO0ZRDrma0Oc1ASGp4R-7ioP3HKC2o3dBYLHUg", | ||
"x": "F0UpAkmilL3GafMgs_NMLqwGpUYPEnFphet8wS21jMg", | ||
"y": "vTGyefjnlCj2-T7gYw3Det6m1UtDOfbB4CTzROlT6QA", | ||
"kid": "y3hMPnp_oK9BM_V9vXu0aErpbzz0mDKe7xjEG44doUg" | ||
} | ||
const privateKeyBuffer = keyUtils.privateKeyUInt8ArrayFromJwk(example); | ||
expect(privateKeyBuffer.length).toBe(32); | ||
const privateKeyJwk = keyUtils.privateKeyJwkFromPrivateKeyHex(privateKeyBuffer.toString('hex')) | ||
expect(privateKeyJwk).toEqual(example); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters