Closed CMCDragonkai closed 2 years ago
This is ready, expect to use Id
as NodeId
in this way:
function publicKeyToFingerprintBytes(
publicKey: PublicKey,
): PublicKeyFingerprintBytes {
const fString = pki.getPublicKeyFingerprint(publicKey, {
type: 'SubjectPublicKeyInfo',
md: md.sha256.create(),
encoding: 'binary',
});
return fString;
}
const b = Buffer.from(publicKeyToFingerprintBytes(publicKey), 'binary');
const nodeId = Id.create(b);
Note that the publicKeyToFingerPrintBytes
currently returns a string due to how node-forge
works. So we have to convert it to buffer which is an Uint8Array
, and therefore can be used in nodeId
.
Actually there's a better function:
const fString = publicKeyToFingerprintBytes(publicKey);
const fTypedArray = forgeUtil.binary.raw.decode(fString);
Then Id.create(fTypedArray)
should work too.
Description
As discussed in https://github.com/MatrixAI/js-polykey/issues/254, we want
Id
to be usable forNodeId
as well. In such a case, we don't actually want the 16 byte limit that we have in ourutils.ts
atm. This is only relevant to UUID. So the limit can be constraint to UUID conversions, and all other functions can operate more freely.Issues Fixed
Tasks
16
byte check totoUUID
, and throwRangeError
if theId
is not 16 bytes16
byte limit from other conversion utilities like string, buffer and multibaseId.test.ts
to test Id creation byitselfId
can be used as Map keys, and POJO keys without any problemsFinal checklist