UNPKG

@hashgraph/sdk

Version:
3 lines (2 loc) 2.26 kB
import{PublicKey as t}from"@hashgraph/cryptography";import{arrayEqual as e}from"./array.js";import r from"./Key.js";import s from"./Cache.js";class i extends r{constructor(t){super(),this._key=t}static fromBytes(e){return new i(t.fromBytes(e))}static fromBytesED25519(e){return new i(t.fromBytesED25519(e))}static fromBytesECDSA(e){return new i(t.fromBytesECDSA(e))}static fromString(e){return new i(t.fromString(e))}static fromStringECDSA(e){return new i(t.fromStringECDSA(e))}static fromStringED25519(e){return new i(t.fromStringED25519(e))}verify(t,e){return this._key.verify(t,e)}verifyTransaction(t){t._requireFrozen(),t.isFrozen()||t.freeze();for(const r of t._signedTransactions.list)if(null!=r.sigMap&&null!=r.sigMap.sigPair){let t=!1;for(const s of r.sigMap.sigPair){const i=s.pubKeyPrefix;if(e(i,this.toBytesRaw())){t=!0;const e=r.bodyBytes;let i=null;if(null!=s.ed25519?i=s.ed25519:null!=s.ECDSASecp256k1&&(i=s.ECDSASecp256k1),null==i)continue;if(!this.verify(e,i))return!1}}if(!t)return!1}return!0}toBytes(){return this._key.toBytes()}toBytesDer(){return this._key.toBytesDer()}toBytesRaw(){return this._key.toBytesRaw()}toEthereumAddress(){return this._key.toEthereumAddress()}toEvmAddress(){return this._key.toEthereumAddress()}toString(){return this._key.toString()}toStringDer(){return this._key.toStringDer()}toStringRaw(){return this._key.toStringRaw()}equals(t){return this._key.equals(t._key)}_toProtobufKey(){switch(this._key._type){case"ED25519":return{ed25519:this._key.toBytesRaw()};case"secp256k1":return{ECDSASecp256k1:this._key.toBytesRaw()};default:throw new Error(`unrecognized key type ${this._key._type}`)}}_toProtobufSignature(t){switch(this._key._type){case"ED25519":return{pubKeyPrefix:this._key.toBytesRaw(),ed25519:t};case"secp256k1":return{pubKeyPrefix:this._key.toBytesRaw(),ECDSASecp256k1:t};default:throw new Error(`unrecognized key type ${this._key._type}`)}}get type(){return this._key._type}toAccountId(t,e){return s.accountIdConstructor(t,e,this)}static unusableKey(){return i.fromStringED25519("0000000000000000000000000000000000000000000000000000000000000000")}}s.setPublicKeyED25519(t=>i.fromBytesED25519(t)),s.setPublicKeyECDSA(t=>i.fromBytesECDSA(t));export{i as default}; //# sourceMappingURL=PublicKey.js.map