@secux/app-eth
Version:
SecuX Hardware Wallet ETH API
17 lines (14 loc) • 1.54 kB
JavaScript
;
/*!
Copyright 2023 SecuX Technology Inc
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 __importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.blake2b=exports.toAgencePubkey=exports.toSubstratePubkey=void 0;const blakejs_1=require("blakejs"),interface_1=require("./interface"),ow_1=__importDefault(require("ow"));function blake2b(message,byteLength=32){let data=message;return"string"==typeof message&&message.startsWith("0x")&&(data=Buffer.from(message.substring(2),"hex")),`0x${(0,blakejs_1.blake2bHex)(data,void 0,byteLength)}`}exports.toSubstratePubkey=function(address){return(0,ow_1.default)(address,interface_1.ow_address),blake2b(`0x65766d3a${address.substring(2).toLowerCase()}`)},exports.toAgencePubkey=function(address){(0,ow_1.default)(address,interface_1.ow_address);const addr=address.substring(2).toLowerCase();return`0x${addr}${blake2b(`0x65766d3a${addr}`).slice(-24)}`},exports.blake2b=blake2b;