2023-08-30 18:37:51 +00:00
|
|
|
import { ed25519 } from "@noble/curves/ed25519";
|
|
|
|
import { concatBytes } from "@noble/curves/abstract/utils";
|
2023-09-02 10:10:20 +00:00
|
|
|
import { CID_HASH_TYPES } from "./constants.js";
|
2023-08-30 18:37:51 +00:00
|
|
|
|
|
|
|
export default class KeyPairEd25519 {
|
|
|
|
private _bytes: Uint8Array;
|
|
|
|
|
|
|
|
constructor(bytes: Uint8Array) {
|
|
|
|
this._bytes = bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get publicKey(): Uint8Array {
|
|
|
|
return concatBytes(
|
2023-09-02 10:10:20 +00:00
|
|
|
Uint8Array.from([CID_HASH_TYPES.ED25519]),
|
2023-09-03 02:35:38 +00:00
|
|
|
this.publicKeyRaw,
|
2023-08-30 18:37:51 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-09-03 02:35:38 +00:00
|
|
|
public get publicKeyRaw(): Uint8Array {
|
|
|
|
return ed25519.getPublicKey(this._bytes);
|
|
|
|
}
|
|
|
|
|
2023-08-30 18:37:51 +00:00
|
|
|
public extractBytes(): Uint8Array {
|
|
|
|
return this._bytes;
|
|
|
|
}
|
|
|
|
}
|