UNPKG

wowok

Version:

Wowok Blockchain TypeScript API

1 lines 1.26 kB
import{fromBase64}from'../../_deps/bcs/index.js';import{falcon512padded}from'@noble/post-quantum/falcon.js';import{bytesEqual,parseSerializedKeypairSignature,PublicKey}from'../../cryptography/publickey.js';import{SIGNATURE_SCHEME_TO_FLAG}from'../../cryptography/signature-scheme.js';const PUBLIC_KEY_SIZE=0x381;export class Falcon512PublicKey extends PublicKey{static ['SIZE']=PUBLIC_KEY_SIZE;['data'];constructor(a){super();if(typeof a==='string')this['data']=fromBase64(a);else a instanceof Uint8Array?this['data']=a:this['data']=Uint8Array['from'](a);if(this['data']['length']!==PUBLIC_KEY_SIZE)throw new Error('Invalid\x20public\x20key\x20input.\x20Expected\x20'+PUBLIC_KEY_SIZE+'\x20bytes,\x20got\x20'+this['data']['length']);}['equals'](a){return super['equals'](a);}['toRawBytes'](){return this['data'];}['flag'](){return SIGNATURE_SCHEME_TO_FLAG['Falcon512'];}async['verify'](a,b){let c;if(typeof b==='string'){const d=parseSerializedKeypairSignature(b);if(d['signatureScheme']!=='Falcon512')throw new Error('Invalid\x20signature\x20scheme');if(!bytesEqual(this['toRawBytes'](),d['publicKey']))throw new Error('Signature\x20does\x20not\x20match\x20public\x20key');c=d['signature'];}else c=b;return falcon512padded['verify'](c,a,this['toRawBytes']());}}