@provablehq/sdk 0.10.3 → 0.10.5-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mainnet/browser.cjs +125 -70
- package/dist/mainnet/browser.cjs.map +1 -1
- package/dist/mainnet/browser.d.cts +1 -1
- package/dist/mainnet/browser.d.ts +1 -1
- package/dist/mainnet/browser.js +126 -72
- package/dist/mainnet/browser.js.map +1 -1
- package/dist/mainnet/network-client.d.cts +8 -0
- package/dist/mainnet/network-client.d.ts +8 -0
- package/dist/mainnet/node.cjs +1 -0
- package/dist/mainnet/node.cjs.map +1 -1
- package/dist/mainnet/node.js +1 -1
- package/dist/mainnet/program-manager.d.cts +27 -1
- package/dist/mainnet/program-manager.d.ts +27 -1
- package/dist/mainnet/wasm.d.cts +1 -1
- package/dist/mainnet/wasm.d.ts +1 -1
- package/dist/testnet/browser.cjs +125 -70
- package/dist/testnet/browser.cjs.map +1 -1
- package/dist/testnet/browser.d.cts +1 -1
- package/dist/testnet/browser.d.ts +1 -1
- package/dist/testnet/browser.js +126 -72
- package/dist/testnet/browser.js.map +1 -1
- package/dist/testnet/network-client.d.cts +8 -0
- package/dist/testnet/network-client.d.ts +8 -0
- package/dist/testnet/node.cjs +1 -0
- package/dist/testnet/node.cjs.map +1 -1
- package/dist/testnet/node.js +1 -1
- package/dist/testnet/program-manager.d.cts +27 -1
- package/dist/testnet/program-manager.d.ts +27 -1
- package/dist/testnet/wasm.d.cts +1 -1
- package/dist/testnet/wasm.d.ts +1 -1
- package/package.json +2 -2
|
@@ -71,6 +71,7 @@ declare class AleoNetworkClient {
|
|
|
71
71
|
verboseErrors: boolean;
|
|
72
72
|
readonly network: string;
|
|
73
73
|
transport: TransportFunction;
|
|
74
|
+
hasCustomTransport: boolean;
|
|
74
75
|
apiKey?: string;
|
|
75
76
|
consumerId?: string;
|
|
76
77
|
jwtData?: JWTData;
|
|
@@ -423,6 +424,13 @@ declare class AleoNetworkClient {
|
|
|
423
424
|
* const latestHeight = networkClient.getLatestHeight();
|
|
424
425
|
*/
|
|
425
426
|
getLatestHeight(): Promise<number>;
|
|
427
|
+
/**
|
|
428
|
+
* Returns state paths for the given record commitments.
|
|
429
|
+
*
|
|
430
|
+
* @param {string[]} commitments - Array of commitment field strings.
|
|
431
|
+
* @returns {Promise<string[]>} Array of state path strings corresponding to the commitments.
|
|
432
|
+
*/
|
|
433
|
+
getStatePaths(commitments: string[]): Promise<string[]>;
|
|
426
434
|
/**
|
|
427
435
|
* Returns the latest block hash.
|
|
428
436
|
*
|
|
@@ -71,6 +71,7 @@ declare class AleoNetworkClient {
|
|
|
71
71
|
verboseErrors: boolean;
|
|
72
72
|
readonly network: string;
|
|
73
73
|
transport: TransportFunction;
|
|
74
|
+
hasCustomTransport: boolean;
|
|
74
75
|
apiKey?: string;
|
|
75
76
|
consumerId?: string;
|
|
76
77
|
jwtData?: JWTData;
|
|
@@ -423,6 +424,13 @@ declare class AleoNetworkClient {
|
|
|
423
424
|
* const latestHeight = networkClient.getLatestHeight();
|
|
424
425
|
*/
|
|
425
426
|
getLatestHeight(): Promise<number>;
|
|
427
|
+
/**
|
|
428
|
+
* Returns state paths for the given record commitments.
|
|
429
|
+
*
|
|
430
|
+
* @param {string[]} commitments - Array of commitment field strings.
|
|
431
|
+
* @returns {Promise<string[]>} Array of state path strings corresponding to the commitments.
|
|
432
|
+
*/
|
|
433
|
+
getStatePaths(commitments: string[]): Promise<string[]>;
|
|
426
434
|
/**
|
|
427
435
|
* Returns the latest block hash.
|
|
428
436
|
*
|
package/dist/mainnet/node.cjs
CHANGED
|
@@ -445,6 +445,7 @@ exports.isProvingResponse = browser.isProvingResponse;
|
|
|
445
445
|
exports.isRecordViewKeyStrategy = browser.isRecordViewKeyStrategy;
|
|
446
446
|
exports.isViewKeyStrategy = browser.isViewKeyStrategy;
|
|
447
447
|
exports.logAndThrow = browser.logAndThrow;
|
|
448
|
+
exports.programChecksum = browser.programChecksum;
|
|
448
449
|
exports.provingKeyLocator = browser.provingKeyLocator;
|
|
449
450
|
exports.sha256Hex = browser.sha256Hex;
|
|
450
451
|
exports.toAddress = browser.toAddress;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.cjs","sources":["../../src/keys/keystore/file.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport * as fsSync from \"node:fs\";\nimport * as path from \"path\";\n\nimport { FunctionKeyPair } from \"../../models/keyPair.js\";\nimport { KeyFingerprint } from \"../verifier/interface.js\";\nimport { InvalidLocatorError } from \"./error.js\";\nimport { KeyLocator, KeyStore, ProvingKeyLocator, VerifyingKeyLocator } from \"./interface.js\";\nimport { MemKeyVerifier } from \"../verifier/memory.js\";\nimport { ProvingKey, VerifyingKey } from \"../../wasm.js\";\n\nexport class LocalFileKeyStore implements KeyStore {\n private directory: string;\n private readonly keyVerifier = new MemKeyVerifier();\n\n /**\n * Creates a new directory at the given path or CURRENTDIR/.aleo if none is provided to store keys.\n * If a custom directory is passed and its last path segment is not \".aleo\", \".aleo\" is appended\n * so keys are stored under that subdirectory (e.g. /home/project → /home/project/.aleo).\n *\n * @param {string} [directory] - Optional custom directory path for key storage. Defaults to \".aleo\" in current working directory.\n * @throws {Error} If directory creation fails.\n */\n constructor(directory?: string) {\n this.directory = directory ?? path.join(process.cwd(), \".aleo\");\n if (directory !== undefined && path.basename(this.directory) !== \".aleo\") {\n this.directory = path.join(this.directory, \".aleo\");\n }\n fsSync.mkdirSync(this.directory, { recursive: true });\n }\n\n /**\n * Validates a single locator component for unsafe filesystem characters.\n *\n * @private\n * @param {string} value - The component value to validate.\n * @param {string} label - Label for error messages (e.g. \"program\", \"functionName\").\n * @throws {InvalidLocatorError} If the value is empty, contains traversal sequences, path separators, or null bytes.\n */\n private validateComponent(value: string, label: string): void {\n if (value === \"\" || value === \".\") {\n throw new InvalidLocatorError(\n `KeyLocator ${label} must not be empty or \".\" (got \"${value}\")`,\n value,\n \"reserved_name\"\n );\n }\n if (value.includes(\"..\")) {\n throw new InvalidLocatorError(\n `KeyLocator ${label} must not contain \"..\" (got \"${value}\")`,\n value,\n \"path_traversal\"\n );\n }\n if (value.includes(\"/\") || value.includes(\"\\\\\") || value.includes(\"\\0\")) {\n throw new InvalidLocatorError(\n `KeyLocator ${label} must not contain path separators or null bytes (got \"${value}\")`,\n value,\n \"path_separator\"\n );\n }\n }\n\n /**\n * Validates that a numeric locator field is not negative.\n *\n * @private\n * @param {number} value - The numeric value to validate.\n * @param {string} label - Label for error messages (e.g. \"edition\", \"amendment\").\n * @throws {InvalidLocatorError} If the value is negative.\n */\n private validateNonNegative(value: number, label: string): void {\n if (!Number.isInteger(value) || value < 0) {\n throw new InvalidLocatorError(\n `KeyLocator ${label} must be a non-negative integer (got ${value})`,\n String(value),\n \"negative_value\"\n );\n }\n }\n\n /**\n * Serializes a {@link KeyLocator} to a filesystem-safe flat string, validating components first.\n *\n * For prover/verifier keys: `{program}.{functionName}.e{edition}.a{amendment}.{network}.{keyType}`\n * For translation keys: `{program}.{functionName}.e{edition}.a{amendment}.{network}.translation.{recordName}.{recordInputPosition}`\n *\n * Note: The optional `checksum` field is excluded — it is used for integrity verification only\n * (via {@link checksumToFingerprint}) and is not part of the key identity.\n *\n * @private\n * @param {KeyLocator} locator - The key locator.\n * @returns {string} A dot-delimited string safe for use as a filename.\n * @throws {InvalidLocatorError} If any component contains unsafe characters.\n */\n private serializeLocator(locator: KeyLocator): string {\n this.validateComponent(locator.program, \"program\");\n this.validateComponent(locator.functionName, \"functionName\");\n this.validateComponent(locator.network, \"network\");\n this.validateNonNegative(locator.edition, \"edition\");\n this.validateNonNegative(locator.amendment, \"amendment\");\n const base = `${locator.program}.${locator.functionName}.e${locator.edition}.a${locator.amendment}.${locator.network}.${locator.keyType}`;\n if (locator.keyType === \"translation\") {\n this.validateComponent(locator.recordName, \"recordName\");\n this.validateNonNegative(locator.recordInputPosition, \"recordInputPosition\");\n return `${base}.${locator.recordName}.${locator.recordInputPosition}`;\n }\n return base;\n }\n\n /**\n * Converts an optional checksum string from a locator into a KeyFingerprint\n * suitable for the key verifier, using the actual key byte length for size.\n *\n * @private\n */\n private checksumToFingerprint(checksum: string | undefined, keyBytes: Uint8Array): KeyFingerprint | undefined {\n if (!checksum) return undefined;\n return { checksum, size: keyBytes.length };\n }\n\n /**\n * Generates the path for a key metadata file based on the locator.\n *\n * @private\n * @param {string} locator - Unique identifier for the key.\n * @returns {string} Full filesystem path to the metadata file.\n */\n private metadataPath(locator: string): string {\n return path.join(this.directory, `${locator}.metadata`);\n }\n\n /**\n * Reads and parses the key fingerprint metadata from storage.\n *\n * @private\n * @param {string} locator - Unique identifier for the key.\n * @returns {Promise<KeyFingerprint | null>} The key fingerprint if found, null if file doesn't exist.\n * @throws {Error} If file read fails for any reason other than not found.\n */\n private async readKeyMetadata(\n locator: string,\n ): Promise<KeyFingerprint | null> {\n try {\n const data = await fs.readFile(this.metadataPath(locator), \"utf-8\");\n return JSON.parse(data) as KeyFingerprint;\n } catch (err: unknown) {\n if (\n err &&\n typeof err === \"object\" &&\n \"code\" in err &&\n err.code === \"ENOENT\"\n )\n return null;\n throw err;\n }\n }\n\n /**\n * Writes key fingerprint metadata to storage.\n *\n * @private\n * @param {string} locator - Unique identifier for the key.\n * @param {KeyFingerprint} metadata - Key fingerprint metadata to store.\n * @returns {Promise<void>}\n * @throws {Error} If directory creation or file write fails.\n */\n private async writeKeyMetadata(\n locator: string,\n metadata: KeyFingerprint,\n ): Promise<void> {\n await fs.mkdir(path.dirname(this.metadataPath(locator)), {\n recursive: true,\n });\n await fs.writeFile(\n this.metadataPath(locator),\n JSON.stringify(metadata, null, 0),\n \"utf-8\",\n );\n }\n\n private async readFileOptional(\n filepath: string,\n ): Promise<Uint8Array | null> {\n try {\n const data = await fs.readFile(filepath);\n return new Uint8Array(data);\n } catch (err: any) {\n if (err.code === \"ENOENT\") return null;\n throw err;\n }\n }\n\n /**\n * Atomically writes data to a file, ensuring the parent directories exist.\n *\n * @private\n * @param {string} filepath - Full path to the file to write\n * @param {Uint8Array} data - Binary data to write to the file\n * @returns {Promise<void>} Resolves when write is complete\n * @throws {Error} If directory creation or file write fails\n */\n private async writeFileAtomic(\n filepath: string,\n data: Uint8Array,\n ): Promise<void> {\n const dir = path.dirname(filepath);\n await fs.mkdir(dir, { recursive: true });\n const tempPath = path.join(\n dir,\n `.${path.basename(filepath)}.${process.pid}.${Date.now()}.${Math.random().toString(16).slice(2)}.tmp`\n );\n await fs.writeFile(tempPath, data);\n try {\n await fs.rename(tempPath, filepath);\n } catch (err: unknown) {\n const code = err && typeof err === \"object\" && \"code\" in err ? (err as NodeJS.ErrnoException).code : undefined;\n // Windows often throws EEXIST when target exists; EPERM/EACCES happen with locks/AV.\n if (code === \"EEXIST\" || code === \"EPERM\" || code === \"EACCES\") {\n await fs.unlink(filepath).catch(() => {});\n try {\n await fs.rename(tempPath, filepath);\n } catch (err2) {\n await fs.unlink(tempPath).catch(() => {});\n throw err2;\n }\n } else {\n await fs.unlink(tempPath).catch(() => {});\n throw err;\n }\n }\n }\n\n /**\n * Recursively removes all files and subdirectories under the given directory, then removes the directory itself.\n * Uses fs.rm with recursive: true and force: true so that symbolic links are removed without following them,\n * avoiding deletion of content outside the keystore.\n *\n * @private\n * @param {string} dir - Directory path to clear\n * @returns {Promise<void>} Resolves when clearing is complete\n * @throws {Error} If directory removal fails for reasons other than non-existence\n */\n private async clearDirectory(dir: string): Promise<void> {\n try {\n await fs.rm(dir, { recursive: true, force: true });\n } catch (err: unknown) {\n const code = err && typeof err === \"object\" && \"code\" in err ? (err as NodeJS.ErrnoException).code : undefined;\n if (code === \"ENOENT\") {\n return;\n }\n throw err;\n }\n }\n\n // -------------------------------------------------------\n // KEYSTORE INTERFACE\n // -------------------------------------------------------\n\n /**\n * Retrieves the key bytes from storage and optionally verifies them.\n *\n * @param {KeyLocator} locator - The key locator with optional checksum for verification.\n * @returns {Promise<Uint8Array | null>} The key bytes if found and verified, null if not found.\n * @throws {KeyVerificationError} If verification fails.\n */\n async getKeyBytes(locator: KeyLocator): Promise<Uint8Array | null> {\n const fileKey = this.serializeLocator(locator);\n\n // Attempt to read key bytes from storage (under this.directory).\n const keyBytes = await this.readFileOptional(path.join(this.directory, fileKey));\n\n // If no key bytes were found, return null.\n if (!keyBytes) return null;\n\n // Use caller-provided checksum or metadata stored on disk for verification.\n const fingerprint =\n this.checksumToFingerprint(locator.checksum, keyBytes) ?? (await this.getKeyMetadata(locator));\n if (fingerprint) {\n await this.keyVerifier.verifyKeyBytes({\n keyBytes,\n locator: fileKey,\n fingerprint,\n });\n }\n\n // Return the verified key bytes.\n return keyBytes;\n }\n\n /**\n * Retrieves and verifies a proving key from storage.\n *\n * @param {ProvingKeyLocator} locator - The proving key locator.\n * @returns {Promise<ProvingKey | null>} The proving key if found and verified, null if not found.\n * @throws {KeyVerificationError} If verification fails.\n * @throws {Error} If key bytes cannot be parsed into a valid ProvingKey.\n */\n async getProvingKey(locator: ProvingKeyLocator): Promise<ProvingKey | null> {\n const proverBytes = await this.getKeyBytes(locator);\n if (!proverBytes) return null;\n return ProvingKey.fromBytes(proverBytes);\n }\n\n /**\n * Retrieves and verifies a verifying key from storage.\n *\n * @param {VerifyingKeyLocator} locator - The verifying key locator.\n * @returns {Promise<VerifyingKey | null>} The verifying key if found and verified, null if not found.\n * @throws {KeyVerificationError} If verification fails.\n * @throws {Error} If key bytes cannot be parsed into a valid VerifyingKey.\n */\n async getVerifyingKey(locator: VerifyingKeyLocator): Promise<VerifyingKey | null> {\n const verifierBytes = await this.getKeyBytes(locator);\n if (!verifierBytes) return null;\n return VerifyingKey.fromBytes(verifierBytes);\n }\n\n /**\n * Stores proving and verifying keys in key storage.\n *\n * @param {ProvingKeyLocator} proverLocator The locator for the proving key.\n * @param {VerifyingKeyLocator} verifierLocator The locator for the verifying key.\n * @param {FunctionKeyPair} keys The proving and verifying keys.\n */\n async setKeys(\n proverLocator: ProvingKeyLocator,\n verifierLocator: VerifyingKeyLocator,\n keys: FunctionKeyPair,\n ): Promise<void> {\n const proverKey = this.serializeLocator(proverLocator);\n const verifierKey = this.serializeLocator(verifierLocator);\n\n // Convert the WASM keys to raw bytes.\n const [provingKey, verifyingKey] = keys;\n const [provingKeyBytes, verifyingKeyBytes] = [\n provingKey.toBytes(),\n verifyingKey.toBytes(),\n ];\n\n // Compute the fingerprints for the proving and verifying keys, verify against expected checksums if provided.\n const [proverFingerPrint, verifierFingerPrint] = await Promise.all([\n this.keyVerifier.computeKeyMetadata({\n keyBytes: provingKeyBytes,\n locator: proverKey,\n fingerprint: this.checksumToFingerprint(proverLocator.checksum, provingKeyBytes),\n }),\n this.keyVerifier.computeKeyMetadata({\n keyBytes: verifyingKeyBytes,\n locator: verifierKey,\n fingerprint: this.checksumToFingerprint(verifierLocator.checksum, verifyingKeyBytes),\n }),\n ]);\n\n // Write the proving and verifying key bytes and their metadata to storage (under this.directory).\n await this.writeFileAtomic(path.join(this.directory, proverKey), provingKeyBytes);\n await this.writeFileAtomic(path.join(this.directory, verifierKey), verifyingKeyBytes);\n await this.writeKeyMetadata(proverKey, proverFingerPrint);\n await this.writeKeyMetadata(verifierKey, verifierFingerPrint);\n }\n\n /**\n * Store a raw key in storage along with its fingerprint metadata for future verification.\n *\n * @param {Uint8Array} keyBytes The raw key bytes.\n * @param {KeyLocator} locator The unique locator for the key.\n * @returns {Promise<void>}\n * @throws {Error} If computing key metadata or writing to storage fails\n */\n async setKeyBytes(keyBytes: Uint8Array, locator: KeyLocator): Promise<void> {\n const fileKey = this.serializeLocator(locator);\n\n // Compute the key metadata including fingerprint\n const computedMetadata = await this.keyVerifier.computeKeyMetadata({\n keyBytes: keyBytes,\n locator: fileKey,\n fingerprint: this.checksumToFingerprint(locator.checksum, keyBytes),\n });\n\n // Write the key bytes and metadata atomically (key file under this.directory).\n await this.writeFileAtomic(path.join(this.directory, fileKey), keyBytes);\n await this.writeKeyMetadata(fileKey, computedMetadata);\n }\n\n /**\n * Returns stored metadata for a key, if any.\n *\n * @param {KeyLocator} locator The unique locator for the key.\n * @returns {Promise<KeyFingerprint | null>} The stored fingerprint metadata, or null if none exists.\n */\n async getKeyMetadata(locator: KeyLocator): Promise<KeyFingerprint | null> {\n const fileKey = this.serializeLocator(locator);\n return this.readKeyMetadata(fileKey);\n }\n\n /**\n * Checks if a key exists for the given locator.\n *\n * @param {KeyLocator} locator - The unique key locator.\n * @returns {Promise<boolean>} True if key exists, false otherwise.\n */\n async has(locator: KeyLocator): Promise<boolean> {\n const fileKey = this.serializeLocator(locator);\n const keyPath = path.join(this.directory, fileKey);\n return await fs\n .access(keyPath)\n .then(() => true)\n .catch(() => false);\n }\n\n /**\n * Deletes a key and its associated metadata from storage. Silently ignores errors if files don't exist.\n *\n * @param {KeyLocator} locator - The unique key locator.\n * @returns {Promise<void>}\n */\n async delete(locator: KeyLocator): Promise<void> {\n const fileKey = this.serializeLocator(locator);\n const p = path.join(this.directory, fileKey);\n const m = this.metadataPath(fileKey);\n\n await fs.unlink(p).catch(() => {});\n await fs.unlink(m).catch(() => {});\n }\n\n /**\n * Clears the key storage directory by recursively removing all files and subdirectories under it, then removes the keystore directory itself.\n *\n * @returns {Promise<void>}\n * @throws {Error} If directory listing fails for reasons other than non-existence.\n */\n async clear(): Promise<void> {\n await this.clearDirectory(this.directory);\n }\n}\n"],"names":["MemKeyVerifier","path","fsSync","InvalidLocatorError","fs","ProvingKey","VerifyingKey"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAWa,iBAAiB,CAAA;AAClB,IAAA,SAAS;AACA,IAAA,WAAW,GAAG,IAAIA,sBAAc,EAAE;AAEnD;;;;;;;AAOG;AACH,IAAA,WAAA,CAAY,SAAkB,EAAA;AAC1B,QAAA,IAAI,CAAC,SAAS,GAAG,SAAS,IAAIC,eAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC;AAC/D,QAAA,IAAI,SAAS,KAAK,SAAS,IAAIA,eAAI,CAAC,QAAQ,CAA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"node.cjs","sources":["../../src/keys/keystore/file.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport * as fsSync from \"node:fs\";\nimport * as path from \"path\";\n\nimport { FunctionKeyPair } from \"../../models/keyPair.js\";\nimport { KeyFingerprint } from \"../verifier/interface.js\";\nimport { InvalidLocatorError } from \"./error.js\";\nimport { KeyLocator, KeyStore, ProvingKeyLocator, VerifyingKeyLocator } from \"./interface.js\";\nimport { MemKeyVerifier } from \"../verifier/memory.js\";\nimport { ProvingKey, VerifyingKey } from \"../../wasm.js\";\n\nexport class LocalFileKeyStore implements KeyStore {\n private directory: string;\n private readonly keyVerifier = new MemKeyVerifier();\n\n /**\n * Creates a new directory at the given path or CURRENTDIR/.aleo if none is provided to store keys.\n * If a custom directory is passed and its last path segment is not \".aleo\", \".aleo\" is appended\n * so keys are stored under that subdirectory (e.g. /home/project → /home/project/.aleo).\n *\n * @param {string} [directory] - Optional custom directory path for key storage. Defaults to \".aleo\" in current working directory.\n * @throws {Error} If directory creation fails.\n */\n constructor(directory?: string) {\n this.directory = directory ?? path.join(process.cwd(), \".aleo\");\n if (directory !== undefined && path.basename(this.directory) !== \".aleo\") {\n this.directory = path.join(this.directory, \".aleo\");\n }\n fsSync.mkdirSync(this.directory, { recursive: true });\n }\n\n /**\n * Validates a single locator component for unsafe filesystem characters.\n *\n * @private\n * @param {string} value - The component value to validate.\n * @param {string} label - Label for error messages (e.g. \"program\", \"functionName\").\n * @throws {InvalidLocatorError} If the value is empty, contains traversal sequences, path separators, or null bytes.\n */\n private validateComponent(value: string, label: string): void {\n if (value === \"\" || value === \".\") {\n throw new InvalidLocatorError(\n `KeyLocator ${label} must not be empty or \".\" (got \"${value}\")`,\n value,\n \"reserved_name\"\n );\n }\n if (value.includes(\"..\")) {\n throw new InvalidLocatorError(\n `KeyLocator ${label} must not contain \"..\" (got \"${value}\")`,\n value,\n \"path_traversal\"\n );\n }\n if (value.includes(\"/\") || value.includes(\"\\\\\") || value.includes(\"\\0\")) {\n throw new InvalidLocatorError(\n `KeyLocator ${label} must not contain path separators or null bytes (got \"${value}\")`,\n value,\n \"path_separator\"\n );\n }\n }\n\n /**\n * Validates that a numeric locator field is not negative.\n *\n * @private\n * @param {number} value - The numeric value to validate.\n * @param {string} label - Label for error messages (e.g. \"edition\", \"amendment\").\n * @throws {InvalidLocatorError} If the value is negative.\n */\n private validateNonNegative(value: number, label: string): void {\n if (!Number.isInteger(value) || value < 0) {\n throw new InvalidLocatorError(\n `KeyLocator ${label} must be a non-negative integer (got ${value})`,\n String(value),\n \"negative_value\"\n );\n }\n }\n\n /**\n * Serializes a {@link KeyLocator} to a filesystem-safe flat string, validating components first.\n *\n * For prover/verifier keys: `{program}.{functionName}.e{edition}.a{amendment}.{network}.{keyType}`\n * For translation keys: `{program}.{functionName}.e{edition}.a{amendment}.{network}.translation.{recordName}.{recordInputPosition}`\n *\n * Note: The optional `checksum` field is excluded — it is used for integrity verification only\n * (via {@link checksumToFingerprint}) and is not part of the key identity.\n *\n * @private\n * @param {KeyLocator} locator - The key locator.\n * @returns {string} A dot-delimited string safe for use as a filename.\n * @throws {InvalidLocatorError} If any component contains unsafe characters.\n */\n private serializeLocator(locator: KeyLocator): string {\n this.validateComponent(locator.program, \"program\");\n this.validateComponent(locator.functionName, \"functionName\");\n this.validateComponent(locator.network, \"network\");\n this.validateNonNegative(locator.edition, \"edition\");\n this.validateNonNegative(locator.amendment, \"amendment\");\n const base = `${locator.program}.${locator.functionName}.e${locator.edition}.a${locator.amendment}.${locator.network}.${locator.keyType}`;\n if (locator.keyType === \"translation\") {\n this.validateComponent(locator.recordName, \"recordName\");\n this.validateNonNegative(locator.recordInputPosition, \"recordInputPosition\");\n return `${base}.${locator.recordName}.${locator.recordInputPosition}`;\n }\n return base;\n }\n\n /**\n * Converts an optional checksum string from a locator into a KeyFingerprint\n * suitable for the key verifier, using the actual key byte length for size.\n *\n * @private\n */\n private checksumToFingerprint(checksum: string | undefined, keyBytes: Uint8Array): KeyFingerprint | undefined {\n if (!checksum) return undefined;\n return { checksum, size: keyBytes.length };\n }\n\n /**\n * Generates the path for a key metadata file based on the locator.\n *\n * @private\n * @param {string} locator - Unique identifier for the key.\n * @returns {string} Full filesystem path to the metadata file.\n */\n private metadataPath(locator: string): string {\n return path.join(this.directory, `${locator}.metadata`);\n }\n\n /**\n * Reads and parses the key fingerprint metadata from storage.\n *\n * @private\n * @param {string} locator - Unique identifier for the key.\n * @returns {Promise<KeyFingerprint | null>} The key fingerprint if found, null if file doesn't exist.\n * @throws {Error} If file read fails for any reason other than not found.\n */\n private async readKeyMetadata(\n locator: string,\n ): Promise<KeyFingerprint | null> {\n try {\n const data = await fs.readFile(this.metadataPath(locator), \"utf-8\");\n return JSON.parse(data) as KeyFingerprint;\n } catch (err: unknown) {\n if (\n err &&\n typeof err === \"object\" &&\n \"code\" in err &&\n err.code === \"ENOENT\"\n )\n return null;\n throw err;\n }\n }\n\n /**\n * Writes key fingerprint metadata to storage.\n *\n * @private\n * @param {string} locator - Unique identifier for the key.\n * @param {KeyFingerprint} metadata - Key fingerprint metadata to store.\n * @returns {Promise<void>}\n * @throws {Error} If directory creation or file write fails.\n */\n private async writeKeyMetadata(\n locator: string,\n metadata: KeyFingerprint,\n ): Promise<void> {\n await fs.mkdir(path.dirname(this.metadataPath(locator)), {\n recursive: true,\n });\n await fs.writeFile(\n this.metadataPath(locator),\n JSON.stringify(metadata, null, 0),\n \"utf-8\",\n );\n }\n\n private async readFileOptional(\n filepath: string,\n ): Promise<Uint8Array | null> {\n try {\n const data = await fs.readFile(filepath);\n return new Uint8Array(data);\n } catch (err: any) {\n if (err.code === \"ENOENT\") return null;\n throw err;\n }\n }\n\n /**\n * Atomically writes data to a file, ensuring the parent directories exist.\n *\n * @private\n * @param {string} filepath - Full path to the file to write\n * @param {Uint8Array} data - Binary data to write to the file\n * @returns {Promise<void>} Resolves when write is complete\n * @throws {Error} If directory creation or file write fails\n */\n private async writeFileAtomic(\n filepath: string,\n data: Uint8Array,\n ): Promise<void> {\n const dir = path.dirname(filepath);\n await fs.mkdir(dir, { recursive: true });\n const tempPath = path.join(\n dir,\n `.${path.basename(filepath)}.${process.pid}.${Date.now()}.${Math.random().toString(16).slice(2)}.tmp`\n );\n await fs.writeFile(tempPath, data);\n try {\n await fs.rename(tempPath, filepath);\n } catch (err: unknown) {\n const code = err && typeof err === \"object\" && \"code\" in err ? (err as NodeJS.ErrnoException).code : undefined;\n // Windows often throws EEXIST when target exists; EPERM/EACCES happen with locks/AV.\n if (code === \"EEXIST\" || code === \"EPERM\" || code === \"EACCES\") {\n await fs.unlink(filepath).catch(() => {});\n try {\n await fs.rename(tempPath, filepath);\n } catch (err2) {\n await fs.unlink(tempPath).catch(() => {});\n throw err2;\n }\n } else {\n await fs.unlink(tempPath).catch(() => {});\n throw err;\n }\n }\n }\n\n /**\n * Recursively removes all files and subdirectories under the given directory, then removes the directory itself.\n * Uses fs.rm with recursive: true and force: true so that symbolic links are removed without following them,\n * avoiding deletion of content outside the keystore.\n *\n * @private\n * @param {string} dir - Directory path to clear\n * @returns {Promise<void>} Resolves when clearing is complete\n * @throws {Error} If directory removal fails for reasons other than non-existence\n */\n private async clearDirectory(dir: string): Promise<void> {\n try {\n await fs.rm(dir, { recursive: true, force: true });\n } catch (err: unknown) {\n const code = err && typeof err === \"object\" && \"code\" in err ? (err as NodeJS.ErrnoException).code : undefined;\n if (code === \"ENOENT\") {\n return;\n }\n throw err;\n }\n }\n\n // -------------------------------------------------------\n // KEYSTORE INTERFACE\n // -------------------------------------------------------\n\n /**\n * Retrieves the key bytes from storage and optionally verifies them.\n *\n * @param {KeyLocator} locator - The key locator with optional checksum for verification.\n * @returns {Promise<Uint8Array | null>} The key bytes if found and verified, null if not found.\n * @throws {KeyVerificationError} If verification fails.\n */\n async getKeyBytes(locator: KeyLocator): Promise<Uint8Array | null> {\n const fileKey = this.serializeLocator(locator);\n\n // Attempt to read key bytes from storage (under this.directory).\n const keyBytes = await this.readFileOptional(path.join(this.directory, fileKey));\n\n // If no key bytes were found, return null.\n if (!keyBytes) return null;\n\n // Use caller-provided checksum or metadata stored on disk for verification.\n const fingerprint =\n this.checksumToFingerprint(locator.checksum, keyBytes) ?? (await this.getKeyMetadata(locator));\n if (fingerprint) {\n await this.keyVerifier.verifyKeyBytes({\n keyBytes,\n locator: fileKey,\n fingerprint,\n });\n }\n\n // Return the verified key bytes.\n return keyBytes;\n }\n\n /**\n * Retrieves and verifies a proving key from storage.\n *\n * @param {ProvingKeyLocator} locator - The proving key locator.\n * @returns {Promise<ProvingKey | null>} The proving key if found and verified, null if not found.\n * @throws {KeyVerificationError} If verification fails.\n * @throws {Error} If key bytes cannot be parsed into a valid ProvingKey.\n */\n async getProvingKey(locator: ProvingKeyLocator): Promise<ProvingKey | null> {\n const proverBytes = await this.getKeyBytes(locator);\n if (!proverBytes) return null;\n return ProvingKey.fromBytes(proverBytes);\n }\n\n /**\n * Retrieves and verifies a verifying key from storage.\n *\n * @param {VerifyingKeyLocator} locator - The verifying key locator.\n * @returns {Promise<VerifyingKey | null>} The verifying key if found and verified, null if not found.\n * @throws {KeyVerificationError} If verification fails.\n * @throws {Error} If key bytes cannot be parsed into a valid VerifyingKey.\n */\n async getVerifyingKey(locator: VerifyingKeyLocator): Promise<VerifyingKey | null> {\n const verifierBytes = await this.getKeyBytes(locator);\n if (!verifierBytes) return null;\n return VerifyingKey.fromBytes(verifierBytes);\n }\n\n /**\n * Stores proving and verifying keys in key storage.\n *\n * @param {ProvingKeyLocator} proverLocator The locator for the proving key.\n * @param {VerifyingKeyLocator} verifierLocator The locator for the verifying key.\n * @param {FunctionKeyPair} keys The proving and verifying keys.\n */\n async setKeys(\n proverLocator: ProvingKeyLocator,\n verifierLocator: VerifyingKeyLocator,\n keys: FunctionKeyPair,\n ): Promise<void> {\n const proverKey = this.serializeLocator(proverLocator);\n const verifierKey = this.serializeLocator(verifierLocator);\n\n // Convert the WASM keys to raw bytes.\n const [provingKey, verifyingKey] = keys;\n const [provingKeyBytes, verifyingKeyBytes] = [\n provingKey.toBytes(),\n verifyingKey.toBytes(),\n ];\n\n // Compute the fingerprints for the proving and verifying keys, verify against expected checksums if provided.\n const [proverFingerPrint, verifierFingerPrint] = await Promise.all([\n this.keyVerifier.computeKeyMetadata({\n keyBytes: provingKeyBytes,\n locator: proverKey,\n fingerprint: this.checksumToFingerprint(proverLocator.checksum, provingKeyBytes),\n }),\n this.keyVerifier.computeKeyMetadata({\n keyBytes: verifyingKeyBytes,\n locator: verifierKey,\n fingerprint: this.checksumToFingerprint(verifierLocator.checksum, verifyingKeyBytes),\n }),\n ]);\n\n // Write the proving and verifying key bytes and their metadata to storage (under this.directory).\n await this.writeFileAtomic(path.join(this.directory, proverKey), provingKeyBytes);\n await this.writeFileAtomic(path.join(this.directory, verifierKey), verifyingKeyBytes);\n await this.writeKeyMetadata(proverKey, proverFingerPrint);\n await this.writeKeyMetadata(verifierKey, verifierFingerPrint);\n }\n\n /**\n * Store a raw key in storage along with its fingerprint metadata for future verification.\n *\n * @param {Uint8Array} keyBytes The raw key bytes.\n * @param {KeyLocator} locator The unique locator for the key.\n * @returns {Promise<void>}\n * @throws {Error} If computing key metadata or writing to storage fails\n */\n async setKeyBytes(keyBytes: Uint8Array, locator: KeyLocator): Promise<void> {\n const fileKey = this.serializeLocator(locator);\n\n // Compute the key metadata including fingerprint\n const computedMetadata = await this.keyVerifier.computeKeyMetadata({\n keyBytes: keyBytes,\n locator: fileKey,\n fingerprint: this.checksumToFingerprint(locator.checksum, keyBytes),\n });\n\n // Write the key bytes and metadata atomically (key file under this.directory).\n await this.writeFileAtomic(path.join(this.directory, fileKey), keyBytes);\n await this.writeKeyMetadata(fileKey, computedMetadata);\n }\n\n /**\n * Returns stored metadata for a key, if any.\n *\n * @param {KeyLocator} locator The unique locator for the key.\n * @returns {Promise<KeyFingerprint | null>} The stored fingerprint metadata, or null if none exists.\n */\n async getKeyMetadata(locator: KeyLocator): Promise<KeyFingerprint | null> {\n const fileKey = this.serializeLocator(locator);\n return this.readKeyMetadata(fileKey);\n }\n\n /**\n * Checks if a key exists for the given locator.\n *\n * @param {KeyLocator} locator - The unique key locator.\n * @returns {Promise<boolean>} True if key exists, false otherwise.\n */\n async has(locator: KeyLocator): Promise<boolean> {\n const fileKey = this.serializeLocator(locator);\n const keyPath = path.join(this.directory, fileKey);\n return await fs\n .access(keyPath)\n .then(() => true)\n .catch(() => false);\n }\n\n /**\n * Deletes a key and its associated metadata from storage. Silently ignores errors if files don't exist.\n *\n * @param {KeyLocator} locator - The unique key locator.\n * @returns {Promise<void>}\n */\n async delete(locator: KeyLocator): Promise<void> {\n const fileKey = this.serializeLocator(locator);\n const p = path.join(this.directory, fileKey);\n const m = this.metadataPath(fileKey);\n\n await fs.unlink(p).catch(() => {});\n await fs.unlink(m).catch(() => {});\n }\n\n /**\n * Clears the key storage directory by recursively removing all files and subdirectories under it, then removes the keystore directory itself.\n *\n * @returns {Promise<void>}\n * @throws {Error} If directory listing fails for reasons other than non-existence.\n */\n async clear(): Promise<void> {\n await this.clearDirectory(this.directory);\n }\n}\n"],"names":["MemKeyVerifier","path","fsSync","InvalidLocatorError","fs","ProvingKey","VerifyingKey"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAWa,iBAAiB,CAAA;AAClB,IAAA,SAAS;AACA,IAAA,WAAW,GAAG,IAAIA,sBAAc,EAAE;AAEnD;;;;;;;AAOG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C;AAClC,QAAA,MAAMA,aAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAK,EAAE,CAAC,CAAC;IACtC;AAEA;;;;;AAKG;AACH,IAAA,MAAM,KAAK,GAAA;QACP,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC;IAC7C;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/mainnet/node.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as fs from 'node:fs/promises';
|
|
|
3
3
|
import * as $fs from 'node:fs';
|
|
4
4
|
import * as path from 'path';
|
|
5
5
|
import { MemKeyVerifier, InvalidLocatorError } from './browser.js';
|
|
6
|
-
export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoNetworkClient, BlockHeightSearch, CREDITS_PROGRAM_KEYS, ChecksumMismatchError, DecryptionNotEnabledError, KEY_STORE, ChecksumMismatchError as KeyVerificationError, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, PRIVATE_TO_PUBLIC_TRANSFER, PRIVATE_TRANSFER, PRIVATE_TRANSFER_TYPES, PUBLIC_TO_PRIVATE_TRANSFER, PUBLIC_TRANSFER, PUBLIC_TRANSFER_AS_SIGNER, ProgramManager, RECORD_DOMAIN, RecordNotFoundError, RecordScanner, RecordScannerRequestError, SealanceMerkleTree, UUIDError, VALID_TRANSFER_TYPES, ViewKeyNotStoredError, buildExecutionRequestFromExternallySignedData, computeExternalSigningInputs, encryptAuthorization, encryptProvingRequest, encryptRegistrationRequest, encryptViewKey, initializeWasm, inputsToFields, isInputIdStrategy, isProveApiErrorBody, isProvingResponse, isRecordViewKeyStrategy, isViewKeyStrategy, logAndThrow, provingKeyLocator, sha256Hex, toAddress, toField, toGroup, toSignature, toViewKey, translationKeyLocator, verifyBatchProof, verifyProof, verifyingKeyLocator, zeroizeBytes } from './browser.js';
|
|
6
|
+
export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoNetworkClient, BlockHeightSearch, CREDITS_PROGRAM_KEYS, ChecksumMismatchError, DecryptionNotEnabledError, KEY_STORE, ChecksumMismatchError as KeyVerificationError, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, PRIVATE_TO_PUBLIC_TRANSFER, PRIVATE_TRANSFER, PRIVATE_TRANSFER_TYPES, PUBLIC_TO_PRIVATE_TRANSFER, PUBLIC_TRANSFER, PUBLIC_TRANSFER_AS_SIGNER, ProgramManager, RECORD_DOMAIN, RecordNotFoundError, RecordScanner, RecordScannerRequestError, SealanceMerkleTree, UUIDError, VALID_TRANSFER_TYPES, ViewKeyNotStoredError, buildExecutionRequestFromExternallySignedData, computeExternalSigningInputs, encryptAuthorization, encryptProvingRequest, encryptRegistrationRequest, encryptViewKey, initializeWasm, inputsToFields, isInputIdStrategy, isProveApiErrorBody, isProvingResponse, isRecordViewKeyStrategy, isViewKeyStrategy, logAndThrow, programChecksum, provingKeyLocator, sha256Hex, toAddress, toField, toGroup, toSignature, toViewKey, translationKeyLocator, verifyBatchProof, verifyProof, verifyingKeyLocator, zeroizeBytes } from './browser.js';
|
|
7
7
|
import { ProvingKey, VerifyingKey } from '@provablehq/wasm/mainnet.js';
|
|
8
8
|
export { Address, Authorization, BHP1024, BHP256, BHP512, BHP768, Boolean, Ciphertext, ComputeKey, DynamicRecord, EncryptionToolkit, ExecutionRequest, ExecutionResponse, Field, Execution as FunctionExecution, GraphKey, Group, I128, I16, I32, I64, I8, OfflineQuery, Pedersen128, Pedersen64, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager as ProgramManagerBase, Proof, ProvingKey, ProvingRequest, RecordCiphertext, RecordPlaintext, Scalar, Signature, Transaction, Transition, U128, U16, U32, U64, U8, Value, VerifyingKey, ViewKey, getOrInitConsensusVersionTestHeights, initThreadPool, snarkVerify, snarkVerifyBatch, stringToField, verifyFunctionExecution } from '@provablehq/wasm/mainnet.js';
|
|
9
9
|
import 'core-js/proposals/json-parse-with-source.js';
|
|
@@ -220,6 +220,20 @@ declare class ProgramManager {
|
|
|
220
220
|
* @param { RecordProvider | undefined } recordProvider A record provider that implements {@link RecordProvider} interface
|
|
221
221
|
*/
|
|
222
222
|
constructor(host?: string | undefined, keyProvider?: FunctionKeyProvider | undefined, recordProvider?: RecordProvider | undefined, networkClientOptions?: AleoNetworkClientOptions | undefined);
|
|
223
|
+
/**
|
|
224
|
+
* Pre-load the inclusion prover for offline execution. Required when the
|
|
225
|
+
* user provides an explicit OfflineQuery (truly offline — can't fetch lazily).
|
|
226
|
+
* For CallbackQuery, snarkVM handles inclusion key loading on demand.
|
|
227
|
+
*/
|
|
228
|
+
private ensureInclusionKeys;
|
|
229
|
+
/**
|
|
230
|
+
* Create a CallbackQuery that delegates all state fetching to the
|
|
231
|
+
* transport-aware network client. WASM calls back into these functions
|
|
232
|
+
* during trace.prepare_async() instead of making its own reqwest calls.
|
|
233
|
+
*
|
|
234
|
+
* This handles ALL programs including those with DynamicRecord inputs.
|
|
235
|
+
*/
|
|
236
|
+
private buildCallbackQuery;
|
|
223
237
|
/**
|
|
224
238
|
* Check if the fee is sufficient to pay for the transaction
|
|
225
239
|
*/
|
|
@@ -1585,4 +1599,16 @@ declare function verifyProof(options: VerificationOptions): boolean;
|
|
|
1585
1599
|
* });
|
|
1586
1600
|
*/
|
|
1587
1601
|
declare function verifyBatchProof(options: BatchVerificationOptions): boolean;
|
|
1588
|
-
|
|
1602
|
+
/**
|
|
1603
|
+
* Get the checksum of an Aleo program.
|
|
1604
|
+
*
|
|
1605
|
+
* @param {string | Program} program Program string or Program object
|
|
1606
|
+
* @returns {Uint8Array} The keccak256 checksum of the program as a 32-byte Uint8Array
|
|
1607
|
+
*
|
|
1608
|
+
* @example
|
|
1609
|
+
* import { programChecksum } from "@provablehq/sdk/mainnet.js";
|
|
1610
|
+
*
|
|
1611
|
+
* const checksum = programChecksum("program foo.aleo; ...");
|
|
1612
|
+
*/
|
|
1613
|
+
declare function programChecksum(program: string | Program): Uint8Array;
|
|
1614
|
+
export { ProgramManager, AuthorizationOptions, FeeAuthorizationOptions, ExecuteOptions, ProvingRequestOptions, ExternalSigningOptions, VerificationOptions, BatchVerificationOptions, inputsToFields, verifyProof, verifyBatchProof, programChecksum };
|
|
@@ -220,6 +220,20 @@ declare class ProgramManager {
|
|
|
220
220
|
* @param { RecordProvider | undefined } recordProvider A record provider that implements {@link RecordProvider} interface
|
|
221
221
|
*/
|
|
222
222
|
constructor(host?: string | undefined, keyProvider?: FunctionKeyProvider | undefined, recordProvider?: RecordProvider | undefined, networkClientOptions?: AleoNetworkClientOptions | undefined);
|
|
223
|
+
/**
|
|
224
|
+
* Pre-load the inclusion prover for offline execution. Required when the
|
|
225
|
+
* user provides an explicit OfflineQuery (truly offline — can't fetch lazily).
|
|
226
|
+
* For CallbackQuery, snarkVM handles inclusion key loading on demand.
|
|
227
|
+
*/
|
|
228
|
+
private ensureInclusionKeys;
|
|
229
|
+
/**
|
|
230
|
+
* Create a CallbackQuery that delegates all state fetching to the
|
|
231
|
+
* transport-aware network client. WASM calls back into these functions
|
|
232
|
+
* during trace.prepare_async() instead of making its own reqwest calls.
|
|
233
|
+
*
|
|
234
|
+
* This handles ALL programs including those with DynamicRecord inputs.
|
|
235
|
+
*/
|
|
236
|
+
private buildCallbackQuery;
|
|
223
237
|
/**
|
|
224
238
|
* Check if the fee is sufficient to pay for the transaction
|
|
225
239
|
*/
|
|
@@ -1585,4 +1599,16 @@ declare function verifyProof(options: VerificationOptions): boolean;
|
|
|
1585
1599
|
* });
|
|
1586
1600
|
*/
|
|
1587
1601
|
declare function verifyBatchProof(options: BatchVerificationOptions): boolean;
|
|
1588
|
-
|
|
1602
|
+
/**
|
|
1603
|
+
* Get the checksum of an Aleo program.
|
|
1604
|
+
*
|
|
1605
|
+
* @param {string | Program} program Program string or Program object
|
|
1606
|
+
* @returns {Uint8Array} The keccak256 checksum of the program as a 32-byte Uint8Array
|
|
1607
|
+
*
|
|
1608
|
+
* @example
|
|
1609
|
+
* import { programChecksum } from "@provablehq/sdk/mainnet.js";
|
|
1610
|
+
*
|
|
1611
|
+
* const checksum = programChecksum("program foo.aleo; ...");
|
|
1612
|
+
*/
|
|
1613
|
+
declare function programChecksum(program: string | Program): Uint8Array;
|
|
1614
|
+
export { ProgramManager, AuthorizationOptions, FeeAuthorizationOptions, ExecuteOptions, ProvingRequestOptions, ExternalSigningOptions, VerificationOptions, BatchVerificationOptions, inputsToFields, verifyProof, verifyBatchProof, programChecksum };
|
package/dist/mainnet/wasm.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Address, Authorization, Boolean, BHP256, BHP512, BHP768, BHP1024, Ciphertext, ComputeKey, DynamicRecord, EncryptionToolkit, ExecutionRequest, Execution, ExecutionResponse, Field, GraphKey, Group, I8, I16, I32, I64, I128, OfflineQuery, Metadata, Pedersen64, Pedersen128, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager, Proof, ProvingKey, ProvingRequest, RecordCiphertext, RecordPlaintext, Scalar, Signature, stringToField, Transaction, Transition, U8, U16, U32, U64, U128, Value, VerifyingKey, ViewKey, initThreadPool, getOrInitConsensusVersionTestHeights, snarkVerify, snarkVerifyBatch, verifyFunctionExecution, } from "@provablehq/wasm/mainnet.js";
|
|
1
|
+
export { Address, Authorization, Boolean, BHP256, BHP512, BHP768, BHP1024, Ciphertext, ComputeKey, DynamicRecord, EncryptionToolkit, ExecutionRequest, Execution, ExecutionResponse, Field, GraphKey, Group, I8, I16, I32, I64, I128, CallbackQuery, OfflineQuery, QueryOption, Metadata, Pedersen64, Pedersen128, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager, Proof, ProvingKey, ProvingRequest, RecordCiphertext, RecordPlaintext, Scalar, Signature, stringToField, Transaction, Transition, U8, U16, U32, U64, U128, Value, VerifyingKey, ViewKey, initThreadPool, getOrInitConsensusVersionTestHeights, snarkVerify, snarkVerifyBatch, verifyFunctionExecution, } from "@provablehq/wasm/mainnet.js";
|
package/dist/mainnet/wasm.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Address, Authorization, Boolean, BHP256, BHP512, BHP768, BHP1024, Ciphertext, ComputeKey, DynamicRecord, EncryptionToolkit, ExecutionRequest, Execution, ExecutionResponse, Field, GraphKey, Group, I8, I16, I32, I64, I128, OfflineQuery, Metadata, Pedersen64, Pedersen128, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager, Proof, ProvingKey, ProvingRequest, RecordCiphertext, RecordPlaintext, Scalar, Signature, stringToField, Transaction, Transition, U8, U16, U32, U64, U128, Value, VerifyingKey, ViewKey, initThreadPool, getOrInitConsensusVersionTestHeights, snarkVerify, snarkVerifyBatch, verifyFunctionExecution, } from "@provablehq/wasm/mainnet.js";
|
|
1
|
+
export { Address, Authorization, Boolean, BHP256, BHP512, BHP768, BHP1024, Ciphertext, ComputeKey, DynamicRecord, EncryptionToolkit, ExecutionRequest, Execution, ExecutionResponse, Field, GraphKey, Group, I8, I16, I32, I64, I128, CallbackQuery, OfflineQuery, QueryOption, Metadata, Pedersen64, Pedersen128, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager, Proof, ProvingKey, ProvingRequest, RecordCiphertext, RecordPlaintext, Scalar, Signature, stringToField, Transaction, Transition, U8, U16, U32, U64, U128, Value, VerifyingKey, ViewKey, initThreadPool, getOrInitConsensusVersionTestHeights, snarkVerify, snarkVerifyBatch, verifyFunctionExecution, } from "@provablehq/wasm/mainnet.js";
|
package/dist/testnet/browser.cjs
CHANGED
|
@@ -842,6 +842,7 @@ class AleoNetworkClient {
|
|
|
842
842
|
verboseErrors;
|
|
843
843
|
network;
|
|
844
844
|
transport;
|
|
845
|
+
hasCustomTransport;
|
|
845
846
|
apiKey;
|
|
846
847
|
consumerId;
|
|
847
848
|
jwtData;
|
|
@@ -856,6 +857,7 @@ class AleoNetworkClient {
|
|
|
856
857
|
this.ctx = {};
|
|
857
858
|
this.verboseErrors = true;
|
|
858
859
|
this.transport = options?.transport ?? defaultTransport;
|
|
860
|
+
this.hasCustomTransport = !!options?.transport;
|
|
859
861
|
if (options) {
|
|
860
862
|
if (options.headers) {
|
|
861
863
|
this.headers = options.headers;
|
|
@@ -863,7 +865,7 @@ class AleoNetworkClient {
|
|
|
863
865
|
else {
|
|
864
866
|
this.headers = {
|
|
865
867
|
// This is replaced by the actual version by a Rollup plugin
|
|
866
|
-
"X-Aleo-SDK-Version": "0.10.
|
|
868
|
+
"X-Aleo-SDK-Version": "0.10.5-rc.1",
|
|
867
869
|
"X-Aleo-environment": environment(),
|
|
868
870
|
};
|
|
869
871
|
}
|
|
@@ -879,7 +881,7 @@ class AleoNetworkClient {
|
|
|
879
881
|
else {
|
|
880
882
|
this.headers = {
|
|
881
883
|
// This is replaced by the actual version by a Rollup plugin
|
|
882
|
-
"X-Aleo-SDK-Version": "0.10.
|
|
884
|
+
"X-Aleo-SDK-Version": "0.10.5-rc.1",
|
|
883
885
|
"X-Aleo-environment": environment(),
|
|
884
886
|
};
|
|
885
887
|
}
|
|
@@ -1596,6 +1598,25 @@ class AleoNetworkClient {
|
|
|
1596
1598
|
this.ctx = {};
|
|
1597
1599
|
}
|
|
1598
1600
|
}
|
|
1601
|
+
/**
|
|
1602
|
+
* Returns state paths for the given record commitments.
|
|
1603
|
+
*
|
|
1604
|
+
* @param {string[]} commitments - Array of commitment field strings.
|
|
1605
|
+
* @returns {Promise<string[]>} Array of state path strings corresponding to the commitments.
|
|
1606
|
+
*/
|
|
1607
|
+
async getStatePaths(commitments) {
|
|
1608
|
+
try {
|
|
1609
|
+
this.ctx = { "X-ALEO-METHOD": "getStatePaths" };
|
|
1610
|
+
const csv = commitments.map(c => encodeURIComponent(c)).join(",");
|
|
1611
|
+
return await this.fetchData(`/statePaths?commitments=${csv}`);
|
|
1612
|
+
}
|
|
1613
|
+
catch (error) {
|
|
1614
|
+
throw new Error(`Error fetching state paths for commitments: ${error}`);
|
|
1615
|
+
}
|
|
1616
|
+
finally {
|
|
1617
|
+
this.ctx = {};
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1599
1620
|
/**
|
|
1600
1621
|
* Returns the latest block hash.
|
|
1601
1622
|
*
|
|
@@ -5188,6 +5209,40 @@ class ProgramManager {
|
|
|
5188
5209
|
this.keyProvider = keyProvider ? keyProvider : new AleoKeyProvider({ transport: networkClientOptions?.transport });
|
|
5189
5210
|
this.recordProvider = recordProvider;
|
|
5190
5211
|
}
|
|
5212
|
+
/**
|
|
5213
|
+
* Pre-load the inclusion prover for offline execution. Required when the
|
|
5214
|
+
* user provides an explicit OfflineQuery (truly offline — can't fetch lazily).
|
|
5215
|
+
* For CallbackQuery, snarkVM handles inclusion key loading on demand.
|
|
5216
|
+
*/
|
|
5217
|
+
async ensureInclusionKeys(isOffline) {
|
|
5218
|
+
if (isOffline && !this.inclusionKeysLoaded) {
|
|
5219
|
+
try {
|
|
5220
|
+
const inclusionKeys = await this.keyProvider.inclusionKeys();
|
|
5221
|
+
testnet_js.ProgramManager.loadInclusionProver(inclusionKeys[0]);
|
|
5222
|
+
this.inclusionKeysLoaded = true;
|
|
5223
|
+
}
|
|
5224
|
+
catch {
|
|
5225
|
+
logAndThrow(`Inclusion key bytes not loaded, please ensure the program manager is initialized with a KeyProvider that includes the inclusion key.`);
|
|
5226
|
+
}
|
|
5227
|
+
}
|
|
5228
|
+
}
|
|
5229
|
+
/**
|
|
5230
|
+
* Create a CallbackQuery that delegates all state fetching to the
|
|
5231
|
+
* transport-aware network client. WASM calls back into these functions
|
|
5232
|
+
* during trace.prepare_async() instead of making its own reqwest calls.
|
|
5233
|
+
*
|
|
5234
|
+
* This handles ALL programs including those with DynamicRecord inputs.
|
|
5235
|
+
*/
|
|
5236
|
+
buildCallbackQuery() {
|
|
5237
|
+
const networkClient = this.networkClient;
|
|
5238
|
+
return new testnet_js.CallbackQuery(
|
|
5239
|
+
// getStateRoot: () => Promise<string>
|
|
5240
|
+
async () => await networkClient.getStateRoot(),
|
|
5241
|
+
// getStatePaths: (commitments: string[]) => Promise<string[]>
|
|
5242
|
+
async (commitments) => await networkClient.getStatePaths(commitments),
|
|
5243
|
+
// getBlockHeight: () => Promise<number>
|
|
5244
|
+
async () => await networkClient.getLatestHeight());
|
|
5245
|
+
}
|
|
5191
5246
|
/**
|
|
5192
5247
|
* Check if the fee is sufficient to pay for the transaction
|
|
5193
5248
|
*/
|
|
@@ -5732,21 +5787,19 @@ class ProgramManager {
|
|
|
5732
5787
|
catch (e) {
|
|
5733
5788
|
logAndThrow(`Error finding fee record. Record finder response: '${e.message}'. Please ensure you're connected to a valid Aleo network and a record with enough balance exists.`);
|
|
5734
5789
|
}
|
|
5735
|
-
if (offlineQuery && !this.inclusionKeysLoaded) {
|
|
5736
|
-
try {
|
|
5737
|
-
const inclusionKeys = await this.keyProvider.inclusionKeys();
|
|
5738
|
-
testnet_js.ProgramManager.loadInclusionProver(inclusionKeys[0]);
|
|
5739
|
-
this.inclusionKeysLoaded = true;
|
|
5740
|
-
console.log("Successfully loaded inclusion key");
|
|
5741
|
-
}
|
|
5742
|
-
catch {
|
|
5743
|
-
logAndThrow(`Inclusion key bytes not loaded, please ensure the program manager is initialized with a KeyProvider that includes the inclusion key.`);
|
|
5744
|
-
}
|
|
5745
|
-
}
|
|
5746
5790
|
// Auto-convert bare string inputs to field elements where the function expects field type.
|
|
5747
5791
|
const preparedInputs = this.prepareInputs(program, functionName, inputs);
|
|
5792
|
+
// Build the query: user-provided OfflineQuery for truly offline execution,
|
|
5793
|
+
// CallbackQuery when a custom transport is configured, or undefined to
|
|
5794
|
+
// let WASM use its internal SnapshotQuery with the default fetch.
|
|
5795
|
+
const query = offlineQuery
|
|
5796
|
+
? testnet_js.QueryOption.offlineQuery(offlineQuery)
|
|
5797
|
+
: this.networkClient.hasCustomTransport
|
|
5798
|
+
? testnet_js.QueryOption.callbackQuery(this.buildCallbackQuery())
|
|
5799
|
+
: undefined;
|
|
5800
|
+
await this.ensureInclusionKeys(!!offlineQuery);
|
|
5748
5801
|
// Build an execution transaction
|
|
5749
|
-
return await testnet_js.ProgramManager.buildExecutionTransaction(executionPrivateKey, program, functionName, preparedInputs, priorityFee, feeRecord, this.host, imports, provingKey, verifyingKey, feeProvingKey, feeVerifyingKey,
|
|
5802
|
+
return await testnet_js.ProgramManager.buildExecutionTransaction(executionPrivateKey, program, functionName, preparedInputs, priorityFee, feeRecord, this.host, imports, provingKey, verifyingKey, feeProvingKey, feeVerifyingKey, query, edition);
|
|
5750
5803
|
}
|
|
5751
5804
|
/**
|
|
5752
5805
|
* Builds an execution transaction for submission to the Aleo network from an Authorization and Fee Authorization.
|
|
@@ -5872,22 +5925,15 @@ class ProgramManager {
|
|
|
5872
5925
|
logAndThrow(`Error finding program imports. Network response: '${e.message}'. Please ensure you're connected to a valid Aleo network and the program is deployed to the network.`);
|
|
5873
5926
|
}
|
|
5874
5927
|
}
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
|
|
5879
|
-
|
|
5880
|
-
|
|
5881
|
-
this.inclusionKeysLoaded = true;
|
|
5882
|
-
console.log("Successfully loaded inclusion key");
|
|
5883
|
-
}
|
|
5884
|
-
catch {
|
|
5885
|
-
logAndThrow(`Inclusion key bytes not loaded, please ensure the program manager is initialized with a KeyProvider that includes the inclusion key.`);
|
|
5886
|
-
}
|
|
5887
|
-
}
|
|
5928
|
+
const query = offlineQuery
|
|
5929
|
+
? testnet_js.QueryOption.offlineQuery(offlineQuery)
|
|
5930
|
+
: this.networkClient.hasCustomTransport
|
|
5931
|
+
? testnet_js.QueryOption.callbackQuery(this.buildCallbackQuery())
|
|
5932
|
+
: undefined;
|
|
5933
|
+
await this.ensureInclusionKeys(!!offlineQuery);
|
|
5888
5934
|
// Build an execution transaction from the authorization.
|
|
5889
5935
|
console.log("Executing authorizations");
|
|
5890
|
-
return await testnet_js.ProgramManager.executeAuthorization(authorization, feeAuthorization, program, provingKey, verifyingKey, feeProvingKey, feeVerifyingKey, imports, this.host,
|
|
5936
|
+
return await testnet_js.ProgramManager.executeAuthorization(authorization, feeAuthorization, program, provingKey, verifyingKey, feeProvingKey, feeVerifyingKey, imports, this.host, query);
|
|
5891
5937
|
}
|
|
5892
5938
|
/**
|
|
5893
5939
|
* Builds a SnarkVM `Authorization` for a specific function.
|
|
@@ -6374,11 +6420,17 @@ class ProgramManager {
|
|
|
6374
6420
|
}
|
|
6375
6421
|
// Auto-convert bare string inputs to field elements where the function expects field type.
|
|
6376
6422
|
const preparedInputs = this.prepareInputs(program, function_name, inputs);
|
|
6423
|
+
const query = offlineQuery
|
|
6424
|
+
? testnet_js.QueryOption.offlineQuery(offlineQuery)
|
|
6425
|
+
: this.networkClient.hasCustomTransport
|
|
6426
|
+
? testnet_js.QueryOption.callbackQuery(this.buildCallbackQuery())
|
|
6427
|
+
: undefined;
|
|
6428
|
+
await this.ensureInclusionKeys(!!offlineQuery);
|
|
6377
6429
|
// Run the program offline and return the result
|
|
6378
6430
|
console.log("Running program offline");
|
|
6379
6431
|
console.log("Proving key: ", provingKey);
|
|
6380
6432
|
console.log("Verifying key: ", verifyingKey);
|
|
6381
|
-
return testnet_js.ProgramManager.executeFunctionOffline(executionPrivateKey, program, function_name, preparedInputs, proveExecution, false, imports, provingKey, verifyingKey, this.host,
|
|
6433
|
+
return testnet_js.ProgramManager.executeFunctionOffline(executionPrivateKey, program, function_name, preparedInputs, proveExecution, false, imports, provingKey, verifyingKey, this.host, query, edition);
|
|
6382
6434
|
}
|
|
6383
6435
|
/**
|
|
6384
6436
|
* Join two credits records into a single credits record
|
|
@@ -6477,20 +6529,14 @@ class ProgramManager {
|
|
|
6477
6529
|
catch (e) {
|
|
6478
6530
|
logAndThrow("Records provided are not valid. Please ensure they are valid plaintext records.");
|
|
6479
6531
|
}
|
|
6480
|
-
|
|
6481
|
-
|
|
6482
|
-
|
|
6483
|
-
|
|
6484
|
-
|
|
6485
|
-
|
|
6486
|
-
console.log("Successfully loaded inclusion key");
|
|
6487
|
-
}
|
|
6488
|
-
catch {
|
|
6489
|
-
logAndThrow(`Inclusion key bytes not loaded, please ensure the program manager is initialized with a KeyProvider that includes the inclusion key.`);
|
|
6490
|
-
}
|
|
6491
|
-
}
|
|
6532
|
+
const query = offlineQuery
|
|
6533
|
+
? testnet_js.QueryOption.offlineQuery(offlineQuery)
|
|
6534
|
+
: this.networkClient.hasCustomTransport
|
|
6535
|
+
? testnet_js.QueryOption.callbackQuery(this.buildCallbackQuery())
|
|
6536
|
+
: undefined;
|
|
6537
|
+
await this.ensureInclusionKeys(!!offlineQuery);
|
|
6492
6538
|
// Build an execution transaction and submit it to the network
|
|
6493
|
-
const tx = await testnet_js.ProgramManager.buildJoinTransaction(executionPrivateKey, recordOne, recordTwo, priorityFee, feeRecord, this.host, joinProvingKey, joinVerifyingKey, feeProvingKey, feeVerifyingKey,
|
|
6539
|
+
const tx = await testnet_js.ProgramManager.buildJoinTransaction(executionPrivateKey, recordOne, recordTwo, priorityFee, feeRecord, this.host, joinProvingKey, joinVerifyingKey, feeProvingKey, feeVerifyingKey, query);
|
|
6494
6540
|
// Check if the account has sufficient credits to pay for the transaction
|
|
6495
6541
|
if (!privateFee) {
|
|
6496
6542
|
await this.checkFee(feeAddress.to_string(), tx.feeAmount());
|
|
@@ -6555,20 +6601,14 @@ class ProgramManager {
|
|
|
6555
6601
|
catch (e) {
|
|
6556
6602
|
logAndThrow("Record provided is not valid. Please ensure it is a valid plaintext record.");
|
|
6557
6603
|
}
|
|
6558
|
-
|
|
6559
|
-
|
|
6560
|
-
|
|
6561
|
-
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
console.log("Successfully loaded inclusion key");
|
|
6565
|
-
}
|
|
6566
|
-
catch {
|
|
6567
|
-
logAndThrow(`Inclusion key bytes not loaded, please ensure the program manager is initialized with a KeyProvider that includes the inclusion key.`);
|
|
6568
|
-
}
|
|
6569
|
-
}
|
|
6604
|
+
const query = offlineQuery
|
|
6605
|
+
? testnet_js.QueryOption.offlineQuery(offlineQuery)
|
|
6606
|
+
: this.networkClient.hasCustomTransport
|
|
6607
|
+
? testnet_js.QueryOption.callbackQuery(this.buildCallbackQuery())
|
|
6608
|
+
: undefined;
|
|
6609
|
+
await this.ensureInclusionKeys(!!offlineQuery);
|
|
6570
6610
|
// Build an execution transaction and submit it to the network
|
|
6571
|
-
const tx = await testnet_js.ProgramManager.buildSplitTransaction(executionPrivateKey, splitAmount, amountRecord, this.host, splitProvingKey, splitVerifyingKey,
|
|
6611
|
+
const tx = await testnet_js.ProgramManager.buildSplitTransaction(executionPrivateKey, splitAmount, amountRecord, this.host, splitProvingKey, splitVerifyingKey, query);
|
|
6572
6612
|
return await this.networkClient.submitTransaction(tx);
|
|
6573
6613
|
}
|
|
6574
6614
|
/**
|
|
@@ -6693,22 +6733,14 @@ class ProgramManager {
|
|
|
6693
6733
|
catch (e) {
|
|
6694
6734
|
logAndThrow(`Error finding fee record. Record finder response: '${e.message}'. Please ensure you're connected to a valid Aleo network and a record with enough balance exists.`);
|
|
6695
6735
|
}
|
|
6696
|
-
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
|
-
|
|
6702
|
-
testnet_js.ProgramManager.loadInclusionProver(inclusionKeys[0]);
|
|
6703
|
-
this.inclusionKeysLoaded = true;
|
|
6704
|
-
console.log("Successfully loaded inclusion key");
|
|
6705
|
-
}
|
|
6706
|
-
catch {
|
|
6707
|
-
logAndThrow(`Inclusion key bytes not loaded, please ensure the program manager is initialized with a KeyProvider that includes the inclusion key.`);
|
|
6708
|
-
}
|
|
6709
|
-
}
|
|
6736
|
+
const query = offlineQuery
|
|
6737
|
+
? testnet_js.QueryOption.offlineQuery(offlineQuery)
|
|
6738
|
+
: this.networkClient.hasCustomTransport
|
|
6739
|
+
? testnet_js.QueryOption.callbackQuery(this.buildCallbackQuery())
|
|
6740
|
+
: undefined;
|
|
6741
|
+
await this.ensureInclusionKeys(!!offlineQuery);
|
|
6710
6742
|
// Build an execution transaction
|
|
6711
|
-
return await testnet_js.ProgramManager.buildTransferTransaction(executionPrivateKey, amount, recipient, transferType, amountRecord, priorityFee, feeRecord, this.host, transferProvingKey, transferVerifyingKey, feeProvingKey, feeVerifyingKey,
|
|
6743
|
+
return await testnet_js.ProgramManager.buildTransferTransaction(executionPrivateKey, amount, recipient, transferType, amountRecord, priorityFee, feeRecord, this.host, transferProvingKey, transferVerifyingKey, feeProvingKey, feeVerifyingKey, query);
|
|
6712
6744
|
}
|
|
6713
6745
|
/**
|
|
6714
6746
|
* Build a transfer_public transaction to transfer credits to another account for later submission to the Aleo network
|
|
@@ -8027,6 +8059,28 @@ function verifyBatchProof(options) {
|
|
|
8027
8059
|
proof.free();
|
|
8028
8060
|
}
|
|
8029
8061
|
}
|
|
8062
|
+
/**
|
|
8063
|
+
* Get the checksum of an Aleo program.
|
|
8064
|
+
*
|
|
8065
|
+
* @param {string | Program} program Program string or Program object
|
|
8066
|
+
* @returns {Uint8Array} The keccak256 checksum of the program as a 32-byte Uint8Array
|
|
8067
|
+
*
|
|
8068
|
+
* @example
|
|
8069
|
+
* import { programChecksum } from "@provablehq/sdk/mainnet.js";
|
|
8070
|
+
*
|
|
8071
|
+
* const checksum = programChecksum("program foo.aleo; ...");
|
|
8072
|
+
*/
|
|
8073
|
+
function programChecksum(program) {
|
|
8074
|
+
const owned = typeof program === "string" ? testnet_js.Program.fromString(program) : undefined;
|
|
8075
|
+
const p = owned ?? program;
|
|
8076
|
+
try {
|
|
8077
|
+
return p.toChecksum();
|
|
8078
|
+
}
|
|
8079
|
+
finally {
|
|
8080
|
+
if (owned)
|
|
8081
|
+
owned.free();
|
|
8082
|
+
}
|
|
8083
|
+
}
|
|
8030
8084
|
|
|
8031
8085
|
// ---------------------------------------------------------------------------
|
|
8032
8086
|
// Converters
|
|
@@ -8492,6 +8546,7 @@ exports.isProvingResponse = isProvingResponse;
|
|
|
8492
8546
|
exports.isRecordViewKeyStrategy = isRecordViewKeyStrategy;
|
|
8493
8547
|
exports.isViewKeyStrategy = isViewKeyStrategy;
|
|
8494
8548
|
exports.logAndThrow = logAndThrow;
|
|
8549
|
+
exports.programChecksum = programChecksum;
|
|
8495
8550
|
exports.provingKeyLocator = provingKeyLocator;
|
|
8496
8551
|
exports.sha256Hex = sha256Hex;
|
|
8497
8552
|
exports.toAddress = toAddress;
|