UNPKG

@secux/utility

Version:

SecuX Hardware Wallet internal tools for SDK

18 lines (15 loc) 2.59 kB
"use strict"; /*! Copyright 2022 SecuX Technology Inc Copyright Chen Wei-En Copyright Wu Tsung-Yu Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */var _bs58Check_hash,__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(receiver,state,value,kind,f){if("m"===kind)throw new TypeError("Private method is not writable");if("a"===kind&&!f)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof state?receiver!==state||!f:!state.has(receiver))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===kind?f.call(receiver,value):f?f.value=value:state.set(receiver,value),value},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(receiver,state,kind,f){if("a"===kind&&!f)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof state?receiver!==state||!f:!state.has(receiver))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===kind?f:"a"===kind?f.call(receiver):f?f.value:state.get(receiver)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.bs58Check=exports.Base58=void 0;const bs58=require("base-x");exports.Base58=bs58("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");exports.bs58Check=class{constructor(hash){_bs58Check_hash.set(this,void 0),__classPrivateFieldSet(this,_bs58Check_hash,hash,"f")}encode(payload,prefix){const data=prefix?Buffer.concat([prefix,payload]):payload,checksum=__classPrivateFieldGet(this,_bs58Check_hash,"f").call(this,data).slice(0,4),dataToEncode=Buffer.concat([data,checksum]);return exports.Base58.encode(dataToEncode)}decode(address){return function(data,check){const payload=data.slice(0,-4),checksum=data.slice(-4),comparedChecksum=check(payload);if(checksum[0]^comparedChecksum[0]|checksum[1]^comparedChecksum[1]|checksum[2]^comparedChecksum[2]|checksum[3]^comparedChecksum[3])throw new Error("decode failed, Invalid data");return payload}(exports.Base58.decode(address),__classPrivateFieldGet(this,_bs58Check_hash,"f"))}},_bs58Check_hash=new WeakMap;