diff --git a/packages/shared-base/src/Identifier/type.ts b/packages/shared-base/src/Identifier/type.ts index db42e88d8d70..94cd9a394b0a 100644 --- a/packages/shared-base/src/Identifier/type.ts +++ b/packages/shared-base/src/Identifier/type.ts @@ -1,4 +1,5 @@ import { decodeArrayBuffer } from '@dimensiondev/kit' +import { Convert } from 'pvtsutils' import { Result, Ok, Err } from 'ts-results' import { EnhanceableSite } from '../Site/type' @@ -189,6 +190,7 @@ export class PostIVIdentifier extends Identifier { } } +const secp256k1ToHex = new Map() /** * This class identify the point on an EC curve. * ec_key:secp256k1/CompressedPoint @@ -204,6 +206,14 @@ export class ECKeyIdentifier extends Identifier { const normalized = this.encodedCompressedKey ?? this.compressedPoint.replace(/\//g, '|') return `ec_key:${this.curve}/${normalized}` } + get publicKeyAsHex() { + const realPoint = this.encodedCompressedKey ?? this.compressedPoint.replace(/\|/g, '/') + if (secp256k1ToHex.has(realPoint)) return secp256k1ToHex.get(realPoint)! + + const hex = '0x' + Convert.ToHex(decodeArrayBuffer(realPoint)) + secp256k1ToHex.set(realPoint, hex) + return hex + } static [$fromString](str: string) { const [curve, point] = str.split('/') if (curve !== 'secp256k1') return null