UNPKG

@opendatalabs/vana-sdk

Version:

A TypeScript library for interacting with Vana Network smart contracts.

108 lines 3.58 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 crypto_utils_exports = {}; __export(crypto_utils_exports, { assertUncompressedPublicKey: () => assertUncompressedPublicKey, bytesEqual: () => bytesEqual, copyBytes: () => copyBytes, generateSeed: () => generateSeed, isValidPrivateKeyFormat: () => isValidPrivateKeyFormat, isValidPublicKeyFormat: () => isValidPublicKeyFormat, parseEncryptedDataBuffer: () => parseEncryptedDataBuffer, processWalletPrivateKey: () => processWalletPrivateKey, processWalletPublicKey: () => processWalletPublicKey }); module.exports = __toCommonJS(crypto_utils_exports); var import_viem = require("viem"); function processWalletPublicKey(publicKey) { return typeof publicKey === "string" ? (0, import_viem.fromHex)( publicKey.startsWith("0x") ? publicKey : `0x${publicKey}`, "bytes" ) : publicKey; } function processWalletPrivateKey(privateKey) { return typeof privateKey === "string" ? (0, import_viem.fromHex)( privateKey.startsWith("0x") ? privateKey : `0x${privateKey}`, "bytes" ) : privateKey; } function parseEncryptedDataBuffer(encryptedBuffer) { return { iv: encryptedBuffer.slice(0, 16), ephemPublicKey: encryptedBuffer.slice(16, 81), // 65 bytes for uncompressed public key ciphertext: encryptedBuffer.slice(81, -32), mac: encryptedBuffer.slice(-32) }; } function generateSeed(message) { const encoder = new TextEncoder(); return encoder.encode(message); } function bytesEqual(a, b) { if (a.length !== b.length) return false; for (let i = 0; i < a.length; i++) { if (a[i] !== b[i]) return false; } return true; } function copyBytes(bytes) { return new Uint8Array(bytes); } function isValidPublicKeyFormat(publicKey) { const len = publicKey.length; if (len === 33) { return publicKey[0] === 2 || publicKey[0] === 3; } if (len === 65) { return publicKey[0] === 4; } if (len === 64) { return true; } return false; } function isValidPrivateKeyFormat(privateKey) { return privateKey.length === 32; } function assertUncompressedPublicKey(publicKey) { if (publicKey.length !== 65) { throw new Error( `Public key must be uncompressed (65 bytes), got ${publicKey.length} bytes. Use provider.normalizeToUncompressed() to convert compressed keys.` ); } if (publicKey[0] !== 4) { throw new Error( `Uncompressed public key must start with 0x04 prefix, got 0x${publicKey[0].toString(16).padStart(2, "0")}` ); } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { assertUncompressedPublicKey, bytesEqual, copyBytes, generateSeed, isValidPrivateKeyFormat, isValidPublicKeyFormat, parseEncryptedDataBuffer, processWalletPrivateKey, processWalletPublicKey }); //# sourceMappingURL=crypto-utils.cjs.map