UNPKG

@roochnetwork/rooch-sdk

Version:
61 lines (60 loc) 2.46 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var keypair_exports = {}; __export(keypair_exports, { Keypair: () => Keypair, LEGACY_PRIVATE_KEY_SIZE: () => LEGACY_PRIVATE_KEY_SIZE, PRIVATE_KEY_SIZE: () => PRIVATE_KEY_SIZE, ROOCH_SECRET_KEY_PREFIX: () => ROOCH_SECRET_KEY_PREFIX, decodeRoochSercetKey: () => decodeRoochSercetKey, encodeRoochSercetKey: () => encodeRoochSercetKey }); module.exports = __toCommonJS(keypair_exports); var import_bech32 = require("bech32"); var import_signer = require("./signer.js"); var import_signatureScheme = require("./signatureScheme.js"); const PRIVATE_KEY_SIZE = 32; const LEGACY_PRIVATE_KEY_SIZE = 64; const ROOCH_SECRET_KEY_PREFIX = "roochsecretkey"; class Keypair extends import_signer.Signer { } function decodeRoochSercetKey(value) { const { prefix, words } = import_bech32.bech32.decode(value); if (prefix !== ROOCH_SECRET_KEY_PREFIX) { throw new Error("invalid private key prefix"); } const extendedSecretKey = new Uint8Array(import_bech32.bech32.fromWords(words)); const secretKey = extendedSecretKey.slice(1); const signatureScheme = import_signatureScheme.SIGNATURE_FLAG_TO_SCHEME[extendedSecretKey[0]]; return { schema: signatureScheme, secretKey }; } function encodeRoochSercetKey(bytes, scheme) { if (bytes.length !== PRIVATE_KEY_SIZE) { throw new Error("Invalid bytes length"); } const flag = import_signatureScheme.SIGNATURE_SCHEME_TO_FLAG[scheme]; const privKeyBytes = new Uint8Array(bytes.length + 1); privKeyBytes.set([flag]); privKeyBytes.set(bytes, 1); return import_bech32.bech32.encode(ROOCH_SECRET_KEY_PREFIX, import_bech32.bech32.toWords(privKeyBytes)); } //# sourceMappingURL=keypair.js.map