UNPKG

p-sdk-wallet

Version:

A comprehensive wallet SDK for React Native (pwc), supporting multi-chain and multi-account features.

50 lines (49 loc) 1.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SimpleKeyring = void 0; const ChainService_1 = require("../chain/ChainService"); /** * Simple keyring for managing a single account from a private key. * Used for importing existing accounts that are not derived from a mnemonic. */ class SimpleKeyring { /** * Creates a new SimpleKeyring instance from a private key. * @param privateKey - The private key to import (hex string without '0x' prefix) */ constructor(privateKey) { this.type = 'Simple'; this.privateKey = privateKey; this.address = ChainService_1.ChainService.getAddress(privateKey); } /** * Returns the private key. This should be used with extreme caution. * @returns The private key as a hex string */ getPrivateKey() { return this.privateKey; } /** * Serializes the keyring into a plain object for encryption and storage. * @returns An object containing the keyring type and private key */ serialize() { return { type: this.type, privateKey: this.privateKey, }; } /** * Deserializes a plain object back into a SimpleKeyring instance. * @param data - The serialized keyring data * @returns A new SimpleKeyring instance * @throws Error if the data is invalid or missing required fields */ static deserialize(data) { if (data.type !== 'Simple' || !data.privateKey) { throw new Error('Invalid data for SimpleKeyring deserialization.'); } return new SimpleKeyring(data.privateKey); } } exports.SimpleKeyring = SimpleKeyring;