Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/shared-base/src/Identifier/type.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -189,6 +190,7 @@ export class PostIVIdentifier extends Identifier {
}
}

const secp256k1ToHex = new Map<string, string>()
/**
* This class identify the point on an EC curve.
* ec_key:secp256k1/CompressedPoint
Expand All @@ -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
Expand Down