UNPKG

@biconomy/abstractjs

Version:

SDK for Biconomy integration with support for account abstraction, smart accounts, ERC-4337.

47 lines 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toP256Signer = exports.isP256Signer = void 0; const nist_js_1 = require("@noble/curves/nist.js"); const viem_1 = require("viem"); const accounts_1 = require("viem/accounts"); const isP256Signer = (signer) => signer?.source === "p256"; exports.isP256Signer = isP256Signer; const toP256Signer = (privateKey) => { const privateKeyBytesArray = (0, viem_1.hexToBytes)(privateKey); const publicKeyBytes = nist_js_1.p256.getPublicKey(privateKeyBytesArray, false); const publicKey = (0, viem_1.toHex)(publicKeyBytes); const xyHex = (0, viem_1.toHex)(publicKeyBytes.slice(1)); const address = (0, viem_1.keccak256)(xyHex).slice(0, 42); const signP256 = (hash) => { const hashBytesArray = (0, viem_1.hexToBytes)(hash); const sigBytes = nist_js_1.p256.sign(hashBytesArray, privateKeyBytesArray, { prehash: false }); return (0, viem_1.toHex)(sigBytes); }; const account = (0, accounts_1.toAccount)({ address, async sign({ hash }) { return signP256(hash); }, async signMessage({ message }) { const hash = (0, viem_1.hashMessage)(message); return signP256(hash); }, async signTransaction(_) { throw new Error("signTransaction is not supported for P256 signer"); }, async signTypedData(typedData) { const hash = (0, viem_1.hashTypedData)(typedData); return signP256(hash); } }); return { ...account, signP256, publicKey, source: "p256" }; }; exports.toP256Signer = toP256Signer; //# sourceMappingURL=toP256Signer.js.map