Skip to content

Instantly share code, notes, and snippets.

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/333a4d28e3fdb275ed20422e97030e04 to your computer and use it in GitHub Desktop.
Save bshambaugh/333a4d28e3fdb275ed20422e97030e04 to your computer and use it in GitHub Desktop.
js-ceramic key-did-resolver/secp256r.ts null errors
test('public key as null', () => {
const inputPublicKeyHex = null;
const base64urlPoint = mapper.publicKeyToXY(inputPublicKeyHex);
// expect(base64urlPoint).toEqual(output);
});
triggers an error:
● public key as null
TypeError: Cannot read property 'slice' of null
77 |
78 | export function publicKeyHexToUint8ArrayPointPair(publicKeyHex: string) {
> 79 | const xHex = publicKeyHex.slice(0,publicKeyHex.length/2);
| ^
80 | const yHex = publicKeyHex.slice(publicKeyHex.length/2,publicKeyHex.length);
81 | const xOctet = u8a.fromString(xHex,'base16');
82 | const yOctet = u8a.fromString(yHex,'base16');
at publicKeyHexToUint8ArrayPointPair (src/secp256r1.ts:79:31)
at Object.publicKeyToXY (src/secp256r1.ts:72:24)
at Object.<anonymous> (src/__tests__/secp256r1.test.ts:62:33)
Note: publicKeyToXY(publicKeyHex: string) first calls publicKeyHexToUint8ArrayPointPair(publicKeyHex: string)
export function publicKeyHexToUint8ArrayPointPair(publicKeyHex: string) {
const xHex = publicKeyHex.slice(0,publicKeyHex.length/2); // BREAKS ON NULL
const yHex = publicKeyHex.slice(publicKeyHex.length/2,publicKeyHex.length); // BREAKS ON NULL
const xOctet = u8a.fromString(xHex,'base16'); // BREAKS ON NULL
const yOctet = u8a.fromString(yHex,'base16'); // BREAKS ON NULL
return { xOctet, yOctet };
}
This produces an error:
const xOctet = u8a.fromString(null,'base16');
This produces an error:
const xOctet = u8a.fromString(xHex,'base16');
publicKeyIntToXY(ecpoint: BigIntPoint) first calls publicKeyIntToUint8ArrayPointPair(ecpoint: BigIntPoint)
test('convert a public key x,y as nulls', () => {
const ecpoint = {
x: null,
y: null
};
const u8aPoint = mapper.publicKeyIntToUint8ArrayPointPair(ecpoint);
});
triggers an error:
● convert a public key x,y as nulls
TypeError: Cannot read property 'toString' of null
92 |
93 | export function publicKeyIntToUint8ArrayPointPair(ecpoint: BigIntPoint) {
> 94 | const xHex = (ecpoint.x).toString();
| ^
95 | const yHex = (ecpoint.y).toString();
96 | const xOctet = u8a.fromString(xHex,'base10');
97 | const yOctet = u8a.fromString(yHex,'base10');
at Object.publicKeyIntToUint8ArrayPointPair (src/secp256r1.ts:94:28)
at Object.<anonymous> (src/__tests__/secp256r1.test.ts:67:28)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment