@@ -7,7 +7,7 @@ import { sha512 } from "ethereum-cryptography/sha512";
77import stringify from "json-stable-stringify" ;
88import log from "loglevel" ;
99
10- import { EncryptedSeed , GetOrSetNonceResult , ImportedShare , KeyType , Point2D , PrivateKeyData , ShareJSON , v2NonceResultType } from "../interfaces" ;
10+ import { AffinePoint , EncryptedSeed , GetOrSetNonceResult , ImportedShare , KeyType , PrivateKeyData , ShareJSON , v2NonceResultType } from "../interfaces" ;
1111import {
1212 bigintToHex ,
1313 bytesToBase64 ,
@@ -68,7 +68,7 @@ function adjustScalarBytes(bytes: Uint8Array): Uint8Array {
6868/** Convenience method that creates public key and other stuff. RFC8032 5.1.5 */
6969export function getEd25519ExtendedPublicKey ( keyBytes : Uint8Array ) : {
7070 scalar : bigint ;
71- point : Point2D ;
71+ point : AffinePoint ;
7272} {
7373 const ed25519Curve = getKeyCurve ( KEY_TYPE . ED25519 ) ;
7474 const len = 32 ;
@@ -90,7 +90,7 @@ export function getEd25519ExtendedPublicKey(keyBytes: Uint8Array): {
9090 return { scalar, point } ;
9191}
9292
93- export function encodeEd25519Point ( point : Point2D ) : Uint8Array {
93+ export function encodeEd25519Point ( point : AffinePoint ) : Uint8Array {
9494 const ed25519Curve = getKeyCurve ( KEY_TYPE . ED25519 ) ;
9595 return ed25519Curve . Point . fromAffine ( point ) . toBytes ( ) ;
9696}
@@ -152,10 +152,9 @@ export const generateSecp256k1KeyData = async (scalarBytes: Uint8Array): Promise
152152 } ;
153153} ;
154154
155- function generateAddressFromPoint ( keyType : KeyType , point : Point2D ) : string {
155+ function generateAddressFromPoint ( keyType : KeyType , point : AffinePoint ) : string {
156156 if ( keyType === KEY_TYPE . SECP256K1 ) {
157- const uncompressed = getSecp256k1 ( ) . Point . fromAffine ( point ) . toBytes ( false ) ;
158- const publicKey = uncompressed . slice ( 1 ) ; // remove 04 prefix
157+ const publicKey = getSecp256k1PublicKeyFromAffinePoint ( point ) ;
159158 const evmAddressLower = `0x${ keccak256 ( publicKey ) . slice ( 64 - 38 ) } ` ;
160159 return toChecksumAddress ( evmAddressLower ) ;
161160 } else if ( keyType === KEY_TYPE . ED25519 ) {
@@ -182,6 +181,12 @@ export function getPostboxKeyFrom1OutOf1(ecCurve: Curve, privKey: string, nonce:
182181 return bigintToHex ( mod ( privKeyBI - nonceBI , ecCurve . Point . CURVE ( ) . n ) ) ;
183182}
184183
184+ export function getSecp256k1PublicKeyFromAffinePoint ( point : AffinePoint ) : Uint8Array {
185+ const uncompressed = getSecp256k1 ( ) . Point . fromAffine ( point ) . toBytes ( false ) ;
186+ const publicKey = uncompressed . slice ( 1 ) ; // remove 04 prefix
187+ return publicKey ;
188+ }
189+
185190export const generateShares = async (
186191 ecCurve : Curve ,
187192 keyType : KeyType ,
0 commit comments