@provablehq/sdk 0.9.14 → 0.9.16-rc
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.d.ts +6 -3
- package/dist/mainnet/browser.js +79 -15
- package/dist/mainnet/browser.js.map +1 -1
- package/dist/mainnet/keys/keystore/file.d.ts +23 -0
- package/dist/mainnet/keys/keystore/keystore.d.ts +81 -0
- package/dist/mainnet/keys/keystore/memory.d.ts +8 -0
- package/dist/mainnet/{function-key-provider.d.ts → keys/provider/function-key-provider.d.ts} +13 -5
- package/dist/mainnet/{offline-key-provider.d.ts → keys/provider/offline-key-provider.d.ts} +5 -2
- package/dist/mainnet/models/keyPair.d.ts +4 -0
- package/dist/mainnet/node-polyfill.js +2 -49
- package/dist/mainnet/node-polyfill.js.map +1 -1
- package/dist/mainnet/node.d.ts +1 -0
- package/dist/mainnet/node.js +129 -2
- package/dist/mainnet/node.js.map +1 -1
- package/dist/mainnet/program-manager.d.ts +2 -1
- package/dist/testnet/browser.d.ts +6 -3
- package/dist/testnet/browser.js +79 -15
- package/dist/testnet/browser.js.map +1 -1
- package/dist/testnet/keys/keystore/file.d.ts +23 -0
- package/dist/testnet/keys/keystore/keystore.d.ts +81 -0
- package/dist/testnet/keys/keystore/memory.d.ts +8 -0
- package/dist/testnet/{function-key-provider.d.ts → keys/provider/function-key-provider.d.ts} +13 -5
- package/dist/testnet/{offline-key-provider.d.ts → keys/provider/offline-key-provider.d.ts} +5 -2
- package/dist/testnet/models/keyPair.d.ts +4 -0
- package/dist/testnet/node-polyfill.js +2 -49
- package/dist/testnet/node-polyfill.js.map +1 -1
- package/dist/testnet/node.d.ts +1 -0
- package/dist/testnet/node.js +129 -2
- package/dist/testnet/node.js.map +1 -1
- package/dist/testnet/program-manager.d.ts +2 -1
- package/package.json +3 -4
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CachedKeyPair, FunctionKeyPair } from "../../models/keyPair.js";
|
|
2
|
+
import { KeyStore } from "./keystore.js";
|
|
3
|
+
import { ProvingKey, VerifyingKey } from "../../wasm.js";
|
|
4
|
+
export declare class LocalFileKeyStore implements KeyStore {
|
|
5
|
+
private directory;
|
|
6
|
+
constructor(directory?: string);
|
|
7
|
+
private proverPath;
|
|
8
|
+
private verifierPath;
|
|
9
|
+
private readFileOptional;
|
|
10
|
+
private writeFileAtomic;
|
|
11
|
+
private clearRecursive;
|
|
12
|
+
getKeys(locator: string): Promise<FunctionKeyPair | null>;
|
|
13
|
+
getKeyBytes(locator: string): Promise<CachedKeyPair | null>;
|
|
14
|
+
getProvingKey(locator: string): Promise<ProvingKey | null>;
|
|
15
|
+
getProvingKeyBytes(locator: string): Promise<Uint8Array | null>;
|
|
16
|
+
getVerifyingKey(locator: string): Promise<VerifyingKey | null>;
|
|
17
|
+
getVerifyingKeyBytes(locator: string): Promise<Uint8Array | null>;
|
|
18
|
+
setKeys(locator: string, keys: FunctionKeyPair): Promise<void>;
|
|
19
|
+
setKeyBytes(locator: string, keys: CachedKeyPair): Promise<void>;
|
|
20
|
+
has(locator: string): Promise<boolean>;
|
|
21
|
+
delete(locator: string): Promise<void>;
|
|
22
|
+
clear(): Promise<void>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { CachedKeyPair, FunctionKeyPair } from "../../models/keyPair.js";
|
|
2
|
+
import { ProvingKey, VerifyingKey } from "../../wasm.js";
|
|
3
|
+
export interface KeyStore {
|
|
4
|
+
/**
|
|
5
|
+
* Returns the proving and verifying keys for a given key locator from key storage.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} locator The unique locator for the desired keypair.
|
|
8
|
+
*
|
|
9
|
+
* @returns {Promise<FunctionKeyPair | null>} Returns the proving and verifying keys for the given locator if they exist or null if they do not.
|
|
10
|
+
*/
|
|
11
|
+
getKeys(locator: string): Promise<FunctionKeyPair | null>;
|
|
12
|
+
/**
|
|
13
|
+
* Returns the proving and verifying key as raw bytes for a given key locator from key storage.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} locator The unique locator for the desired keypair.
|
|
16
|
+
*
|
|
17
|
+
* @returns {Promise<CachedKeyPair | null>} Returns the proving and verifying keys for the given locator as raw bytes if they exist or null if they do not. */
|
|
18
|
+
getKeyBytes(locator: string): Promise<CachedKeyPair | null>;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the `ProvingKey` for a given locator.
|
|
21
|
+
*
|
|
22
|
+
* @param {string} locator The unique locator for the desired `ProvingKey`.
|
|
23
|
+
*
|
|
24
|
+
* @returns {Promise<ProvingKey | null>} Returns the `ProvingKey` for the given locator if it exists or null if it does not.
|
|
25
|
+
*/
|
|
26
|
+
getProvingKey(locator: string): Promise<ProvingKey | null>;
|
|
27
|
+
/**
|
|
28
|
+
* Returns the raw bytes of a `ProvingKey` for a given locator.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} locator The unique locator for the desired `ProvingKey`.
|
|
31
|
+
*
|
|
32
|
+
* @returns {Promise<Uint8Array | null>} Returns the raw bytes of a `ProvingKey` for the given locator if it exists or null if it does not exist.
|
|
33
|
+
*/
|
|
34
|
+
getProvingKeyBytes(locator: string): Promise<Uint8Array | null>;
|
|
35
|
+
/**
|
|
36
|
+
* Returns the `VerifyingKey` for a given locator.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} locator The unique locator for the desired `VerifyingKey`.
|
|
39
|
+
*
|
|
40
|
+
* @returns {Promise<VerifyingKey | null>} Returns the `VerifyingKey` for the given locator if it exists or null if it does not exist.
|
|
41
|
+
*/
|
|
42
|
+
getVerifyingKey(locator: string): Promise<VerifyingKey | null>;
|
|
43
|
+
/**
|
|
44
|
+
* Returns the raw bytes of a `VerifyingKey` for a given locator.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} locator The unique locator for the desired `VerifyingKey`.
|
|
47
|
+
*
|
|
48
|
+
* @returns {Promise<Uint8Array | null>} Returns the raw bytes of a `VerifyingKey` for the given locator if it exists or null if it does not exist.
|
|
49
|
+
*/
|
|
50
|
+
getVerifyingKeyBytes(locator: string): Promise<Uint8Array | null>;
|
|
51
|
+
/**
|
|
52
|
+
* Stores proving and verifying keys in key storage.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} locator The unique locator for the desired keypair.
|
|
55
|
+
* @param {FunctionKeyPair} keys The proving and verifying keys.
|
|
56
|
+
*/
|
|
57
|
+
setKeys(locator: string, keys: FunctionKeyPair): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Stores the raw proving and verifying key bytes in key storage.
|
|
60
|
+
*
|
|
61
|
+
* @param {string} locator The unique locator for the desired keypair.
|
|
62
|
+
* @param {CachedKeyPair} keys The raw proving and verifying key bytes.
|
|
63
|
+
*/
|
|
64
|
+
setKeyBytes(locator: string, keys: CachedKeyPair): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Determines if a given keypair exists or not.
|
|
67
|
+
*
|
|
68
|
+
* @param {string} locator The unique locator for the desired keypair.
|
|
69
|
+
*/
|
|
70
|
+
has(locator: string): Promise<boolean>;
|
|
71
|
+
/**
|
|
72
|
+
* Deletes a keypair corresponding to a given locator.
|
|
73
|
+
*
|
|
74
|
+
* @param {string} locator The unique locator for the desired keypair.
|
|
75
|
+
*/
|
|
76
|
+
delete(locator: string): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Clears all keys in the keystore.
|
|
79
|
+
*/
|
|
80
|
+
clear(): Promise<void>;
|
|
81
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CachedKeyPair } from "../../models/keyPair.js";
|
|
2
|
+
import { KeyStore } from "./keystore.js";
|
|
3
|
+
/**
|
|
4
|
+
* @param {Map<string, CachedKeyPair>} map Any interface which returns a string as cached keypair bytes.
|
|
5
|
+
*
|
|
6
|
+
* @returns {KeyStore} The map decorated as a keystore.
|
|
7
|
+
*/
|
|
8
|
+
export declare function promoteMapToKeyStore(map: Map<string, CachedKeyPair>): KeyStore;
|
package/dist/mainnet/{function-key-provider.d.ts → keys/provider/function-key-provider.d.ts}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Key } from "
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Key } from "../../constants";
|
|
2
|
+
import { CachedKeyPair, FunctionKeyPair } from "../../models/keyPair";
|
|
3
|
+
import { KeyStore } from "../keystore/keystore";
|
|
4
|
+
import { ProvingKey, VerifyingKey } from "../../wasm";
|
|
5
5
|
type AleoKeyProviderInitParams = {
|
|
6
6
|
proverUri?: string;
|
|
7
7
|
verifierUri?: string;
|
|
@@ -134,6 +134,13 @@ interface FunctionKeyProvider {
|
|
|
134
134
|
* const [transferPrivateProvingKey, transferPrivateVerifyingKey] = await keyProvider.functionKeys(searchParams);
|
|
135
135
|
*/
|
|
136
136
|
functionKeys(params?: KeySearchParams): Promise<FunctionKeyPair>;
|
|
137
|
+
/**
|
|
138
|
+
* Gets an object which implements the `KeyStore` interface key store object for accessing proving and verifying
|
|
139
|
+
* keys directly from persistent storage.
|
|
140
|
+
*
|
|
141
|
+
* @return {KeyStore}
|
|
142
|
+
*/
|
|
143
|
+
keyStore(): Promise<KeyStore | undefined>;
|
|
137
144
|
/**
|
|
138
145
|
* Get fee_private function keys from the credits.aleo program
|
|
139
146
|
*
|
|
@@ -202,6 +209,7 @@ declare class AleoKeyProvider implements FunctionKeyProvider {
|
|
|
202
209
|
keyUris: string;
|
|
203
210
|
fetchBytes(url?: string): Promise<Uint8Array>;
|
|
204
211
|
constructor();
|
|
212
|
+
keyStore(): Promise<KeyStore | undefined>;
|
|
205
213
|
/**
|
|
206
214
|
* Use local memory to store keys
|
|
207
215
|
*
|
|
@@ -364,4 +372,4 @@ declare class AleoKeyProvider implements FunctionKeyProvider {
|
|
|
364
372
|
getVerifyingKey(verifierUri: string): Promise<VerifyingKey>;
|
|
365
373
|
unBondPublicKeys(): Promise<FunctionKeyPair>;
|
|
366
374
|
}
|
|
367
|
-
export { AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams,
|
|
375
|
+
export { AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, FunctionKeyProvider, KeySearchParams };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { FunctionKeyProvider, KeySearchParams } from "./function-key-provider.js";
|
|
2
|
+
import { CachedKeyPair, FunctionKeyPair } from "../../models/keyPair.js";
|
|
3
|
+
import { ProvingKey, VerifyingKey } from "../../wasm.js";
|
|
4
|
+
import { KeyStore } from "../keystore/keystore.js";
|
|
3
5
|
/**
|
|
4
6
|
* Search parameters for the offline key provider. This class implements the KeySearchParams interface and includes
|
|
5
7
|
* a convenience method for creating a new instance of this class for each function of the credits.aleo program.
|
|
@@ -138,6 +140,7 @@ declare class OfflineSearchParams implements KeySearchParams {
|
|
|
138
140
|
declare class OfflineKeyProvider implements FunctionKeyProvider {
|
|
139
141
|
cache: Map<string, CachedKeyPair>;
|
|
140
142
|
constructor();
|
|
143
|
+
keyStore(): Promise<KeyStore | undefined>;
|
|
141
144
|
/**
|
|
142
145
|
* Get bond_public function keys from the credits.aleo program. The keys must be cached prior to calling this
|
|
143
146
|
* method for it to work.
|
|
@@ -3,7 +3,6 @@ import { webcrypto } from 'node:crypto';
|
|
|
3
3
|
import * as $fs from 'node:fs';
|
|
4
4
|
import $mime from 'mime/lite';
|
|
5
5
|
import $xmlhttprequest from 'xmlhttprequest-ssl';
|
|
6
|
-
import $request from 'sync-request';
|
|
7
6
|
import * as $worker from 'node:worker_threads';
|
|
8
7
|
import * as $os from 'node:os';
|
|
9
8
|
|
|
@@ -53,54 +52,8 @@ globalThis.fetch = async function (resource, options) {
|
|
|
53
52
|
// @ts-ignore
|
|
54
53
|
if (globalThis.XMLHttpRequest == null) {
|
|
55
54
|
globalThis.XMLHttpRequest = class extends $xmlhttprequest.XMLHttpRequest {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// instead it defines all of the methods inside of the constructor.
|
|
59
|
-
constructor(...args) {
|
|
60
|
-
super(...args);
|
|
61
|
-
const open = this.open;
|
|
62
|
-
const send = this.send;
|
|
63
|
-
let _async = true;
|
|
64
|
-
let _url = null;
|
|
65
|
-
let _mime = "text/xml";
|
|
66
|
-
function reset() {
|
|
67
|
-
_async = true;
|
|
68
|
-
_url = null;
|
|
69
|
-
_mime = "text/xml";
|
|
70
|
-
}
|
|
71
|
-
this.open = function (method, url, async, user, password) {
|
|
72
|
-
// Special behavior for synchronous requests
|
|
73
|
-
if (method === "GET" && !async && !user && !password) {
|
|
74
|
-
_async = false;
|
|
75
|
-
_url = url;
|
|
76
|
-
// Default to the normal polyfill for async requests
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
reset();
|
|
80
|
-
return open.call(this, method, url, async, user, password);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
this.send = function (data) {
|
|
84
|
-
if (_async) {
|
|
85
|
-
return send.call(this, data);
|
|
86
|
-
// Use `sync-request` for synchronous requests.
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
const response = $request("GET", _url, {
|
|
90
|
-
headers: {
|
|
91
|
-
"Content-Type": _mime,
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
const buffer = response.body.buffer;
|
|
95
|
-
const responseText = new TextDecoder("iso-8859-5", { fatal: true }).decode(buffer);
|
|
96
|
-
this.status = 200;
|
|
97
|
-
this.response = this.responseText = responseText;
|
|
98
|
-
reset();
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
this.overrideMimeType = function (mime) {
|
|
102
|
-
_mime = mime;
|
|
103
|
-
};
|
|
55
|
+
constructor(opts) {
|
|
56
|
+
super({ syncPolicy: "enabled", ...opts });
|
|
104
57
|
}
|
|
105
58
|
};
|
|
106
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-polyfill.js","sources":["../../src/polyfill/crypto.ts","../../src/polyfill/fetch.ts","../../src/polyfill/xmlhttprequest.ts","../../src/polyfill/worker.ts","../../src/node-polyfill.ts"],"sourcesContent":["import { webcrypto } from \"node:crypto\";\n\nif ((globalThis as any).crypto == null) {\n (globalThis as any).crypto = webcrypto;\n}\n","import * as $fs from \"node:fs\";\nimport $mime from \"mime/lite\";\n\n\nconst oldFetch = globalThis.fetch;\n\n\nlet supports: Promise<boolean> | null = null;\n\nasync function checkFetch() {\n try {\n await oldFetch(new URL(\"file:\"));\n return true;\n\n } catch (e) {\n return false;\n }\n}\n\nasync function supportsFetch(): Promise<boolean> {\n if (supports === null) {\n supports = checkFetch();\n }\n\n return await supports;\n}\n\n\n// We always polyfill fetch because Node's fetch doesn't support file URLs.\n(globalThis.fetch as any) = async function (resource: URL | RequestInfo, options: RequestInit | undefined): Promise<Response> {\n const request = new Request(resource, options);\n\n const url = new URL(request.url);\n\n if (!(await supportsFetch()) && url.protocol === \"file:\") {\n const readStream = $fs.createReadStream(url);\n\n const headers: HeadersInit = {};\n\n const type = $mime.getType(url.pathname);\n\n if (type) {\n headers[\"Content-Type\"] = type;\n }\n\n return new Response(readStream as any, {\n status: 200,\n statusText: \"OK\",\n headers,\n });\n\n } else {\n return await oldFetch(request);\n }\n};\n","// @ts-ignore\nimport $xmlhttprequest from \"xmlhttprequest-ssl\";\nimport $request from \"sync-request\";\n\nif (globalThis.XMLHttpRequest == null) {\n globalThis.XMLHttpRequest = class extends $xmlhttprequest.XMLHttpRequest {\n // We have to override the methods inside of the `constructor`\n // because `xmlhttprequest-ssl` doesn't use a regular class,\n // instead it defines all of the methods inside of the constructor.\n constructor(...args: Array<any>) {\n super(...args);\n\n const open = (this as any).open;\n const send = (this as any).send;\n\n let _async: boolean = true;\n let _url: null | string = null;\n let _mime: string = \"text/xml\";\n\n function reset() {\n _async = true;\n _url = null;\n _mime = \"text/xml\";\n }\n\n (this as any).open = function (method: string, url: string, async: boolean, user?: string, password?: string) {\n // Special behavior for synchronous requests\n if (method === \"GET\" && !async && !user && !password) {\n _async = false;\n _url = url;\n\n // Default to the normal polyfill for async requests\n } else {\n reset();\n return open.call(this, method, url, async, user, password);\n }\n };\n\n (this as any).send = function (data: any) {\n if (_async) {\n return send.call(this, data);\n\n // Use `sync-request` for synchronous requests.\n } else {\n const response = $request(\"GET\", _url!, {\n headers: {\n \"Content-Type\": _mime,\n }\n });\n\n const buffer = (response.body as Buffer).buffer as any;\n\n const responseText = new TextDecoder(\"iso-8859-5\", { fatal: true }).decode(buffer);\n\n (this as any).status = 200;\n (this as any).response = (this as any).responseText = responseText;\n\n reset();\n }\n };\n\n (this as any).overrideMimeType = function (mime: string) {\n _mime = mime;\n };\n }\n } as any;\n}\n","import * as $worker from \"node:worker_threads\";\nimport * as $os from \"node:os\";\n\n// This is technically not a part of the Worker polyfill,\n// but Workers are used for multi-threading, so this is often\n// needed when writing Worker code.\nif (globalThis.navigator == null) {\n globalThis.navigator = {\n hardwareConcurrency: $os.cpus().length,\n } as Navigator;\n}\n\nif (globalThis.Worker == null) {\n globalThis.Worker = class Worker extends EventTarget {\n private _worker: import(\"node:worker_threads\").Worker;\n\n constructor(url: string | URL, options?: WorkerOptions | undefined) {\n super();\n\n if (url instanceof URL) {\n if (url.protocol !== \"file:\") {\n throw new Error(\"Worker only supports file: URLs\");\n }\n\n url = url.href;\n\n } else {\n throw new Error(\"Filepaths are unreliable, use `new URL(\\\"...\\\", import.meta.url)` instead.\");\n }\n\n if (!options || options.type !== \"module\") {\n throw new Error(\"Workers must use \\`type: \\\"module\\\"\\`\");\n }\n\n const code = `\n import(\"node:worker_threads\")\n .then(({ workerData }) => {\n return import(workerData.polyfill)\n .then(() => import(workerData.url))\n })\n .catch((e) => {\n // TODO maybe it should send a message to the parent?\n console.error(e.stack);\n });\n `;\n\n this._worker = new $worker.Worker(code, {\n eval: true,\n workerData: {\n url,\n polyfill: new URL(\"node-polyfill.js\", import.meta.url).href,\n },\n });\n\n this._worker.on(\"message\", (data) => {\n this.dispatchEvent(new MessageEvent(\"message\", { data }));\n });\n\n this._worker.on(\"messageerror\", (error) => {\n throw new Error(\"UNIMPLEMENTED\");\n });\n\n this._worker.on(\"error\", (error) => {\n // TODO attach the error to the event somehow\n const event = new Event(\"error\");\n this.dispatchEvent(event);\n });\n }\n\n set onmessage(f: () => void) {\n throw new Error(\"UNIMPLEMENTED\");\n }\n\n set onmessageerror(f: () => void) {\n throw new Error(\"UNIMPLEMENTED\");\n }\n\n set onerror(f: () => void) {\n throw new Error(\"UNIMPLEMENTED\");\n }\n\n postMessage(message: any, transfer: Array<Transferable>): void;\n postMessage(message: any, options?: StructuredSerializeOptions | undefined): void;\n postMessage(value: any, transfer: any) {\n this._worker.postMessage(value, transfer);\n }\n\n terminate() {\n this._worker.terminate();\n }\n\n // This is Node-specific, it allows the process to exit\n // even if the Worker is still running.\n unref() {\n this._worker.unref();\n }\n };\n}\n\n\nif (!$worker.isMainThread) {\n const globals = globalThis as unknown as DedicatedWorkerGlobalScope;\n\n // This is used to create the onmessage, onmessageerror, and onerror setters\n const makeSetter = (prop: string, event: string) => {\n let oldvalue: () => void;\n\n Object.defineProperty(globals, prop, {\n get() {\n return oldvalue;\n },\n set(value) {\n if (oldvalue) {\n globals.removeEventListener(event, oldvalue);\n }\n\n oldvalue = value;\n\n if (oldvalue) {\n globals.addEventListener(event, oldvalue);\n }\n },\n });\n };\n\n // This makes sure that `f` is only run once\n const memoize = (f: () => void) => {\n let run = false;\n\n return () => {\n if (!run) {\n run = true;\n f();\n }\n };\n };\n\n\n // We only start listening for messages / errors when the worker calls addEventListener\n const startOnMessage = memoize(() => {\n $worker.parentPort!.on(\"message\", (data) => {\n workerEvents.dispatchEvent(new MessageEvent(\"message\", { data }));\n });\n });\n\n const startOnMessageError = memoize(() => {\n throw new Error(\"UNIMPLEMENTED\");\n });\n\n const startOnError = memoize(() => {\n $worker.parentPort!.on(\"error\", (data) => {\n workerEvents.dispatchEvent(new Event(\"error\"));\n });\n });\n\n\n // Node workers don't have top-level events, so we have to make our own\n const workerEvents = new EventTarget();\n\n globals.close = () => {\n process.exit();\n };\n\n globals.addEventListener = (type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined) => {\n workerEvents.addEventListener(type, callback, options);\n\n if (type === \"message\") {\n startOnMessage();\n } else if (type === \"messageerror\") {\n startOnMessageError();\n } else if (type === \"error\") {\n startOnError();\n }\n };\n\n globals.removeEventListener = (type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined) => {\n workerEvents.removeEventListener(type, callback, options);\n };\n\n function postMessage(message: any, transfer: Transferable[]): void;\n function postMessage(message: any, options?: StructuredSerializeOptions | undefined): void;\n function postMessage(value: any, transfer: any) {\n $worker.parentPort!.postMessage(value, transfer);\n }\n\n globals.postMessage = postMessage;\n\n makeSetter(\"onmessage\", \"message\");\n makeSetter(\"onmessageerror\", \"messageerror\");\n makeSetter(\"onerror\", \"error\");\n}\n","import \"./polyfill/shared.js\";\nimport \"./polyfill/crypto.js\";\nimport \"./polyfill/fetch.js\";\nimport \"./polyfill/xmlhttprequest.js\";\nimport \"./polyfill/worker.js\";\n\nif (!globalThis.self) {\n (globalThis as any).self = globalThis;\n}\n"],"names":[],"mappings":";;;;;;;;;AAEA,IAAK,UAAkB,CAAC,MAAM,IAAI,IAAI,EAAE;AACnC,IAAA,UAAkB,CAAC,MAAM,GAAG,SAAS;AAC1C;;ACAA,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK;AAGjC,IAAI,QAAQ,GAA4B,IAAI;AAE5C,eAAe,UAAU,GAAA;AACrB,IAAA,IAAI;QACA,MAAM,QAAQ,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;AAChC,QAAA,OAAO,IAAI;IAEf;IAAE,OAAO,CAAC,EAAE;AACR,QAAA,OAAO,KAAK;IAChB;AACJ;AAEA,eAAe,aAAa,GAAA;AACxB,IAAA,IAAI,QAAQ,KAAK,IAAI,EAAE;QACnB,QAAQ,GAAG,UAAU,EAAE;IAC3B;IAEA,OAAO,MAAM,QAAQ;AACzB;AAGA;A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AAO,CAAC,KAAK,GAAG,MAAK;QACjB,OAAO,CAAC,IAAI,EAAE;AAClB,IAAA,CAAC;IAED,OAAO,CAAC,gBAAgB,GAAG,CAAC,IAAY,EAAE,QAAmD,EAAE,OAAoD,KAAI;QACnJ,YAAY,CAAC,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC;AAEtD,QAAA,IAAI,IAAI,KAAK,SAAS,EAAE;AACpB,YAAA,cAAc,EAAE;QACpB;AAAO,aAAA,IAAI,IAAI,KAAK,cAAc,EAAE;AAChC,YAAA,mBAAmB,EAAE;QACzB;AAAO,aAAA,IAAI,IAAI,KAAK,OAAO,EAAE;AACzB,YAAA,YAAY,EAAE;QAClB;AACJ,IAAA,CAAC;IAED,OAAO,CAAC,mBAAmB,GAAG,CAAC,IAAY,EAAE,QAAmD,EAAE,OAAoD,KAAI;QACtJ,YAAY,CAAC,mBAAmB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC;AAC7D,IAAA,CAAC;AAID,IAAA,SAAS,WAAW,CAAC,KAAU,EAAE,QAAa,EAAA;QAC1C,OAAO,CAAC,UAAW,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC;IACpD;AAEA,IAAA,OAAO,CAAC,WAAW,GAAG,WAAW;AAEjC,IAAA,UAAU,CAAC,WAAW,EAAE,SAAS,CAAC;AAClC,IAAA,UAAU,CAAC,gBAAgB,EAAE,cAAc,CAAC;AAC5C,IAAA,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC;AAClC;;ACxLA,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE;AACjB,IAAA,UAAkB,CAAC,IAAI,GAAG,UAAU;AACzC"}
|
|
1
|
+
{"version":3,"file":"node-polyfill.js","sources":["../../src/polyfill/crypto.ts","../../src/polyfill/fetch.ts","../../src/polyfill/xmlhttprequest.ts","../../src/polyfill/worker.ts","../../src/node-polyfill.ts"],"sourcesContent":["import { webcrypto } from \"node:crypto\";\n\nif ((globalThis as any).crypto == null) {\n (globalThis as any).crypto = webcrypto;\n}\n","import * as $fs from \"node:fs\";\nimport $mime from \"mime/lite\";\n\n\nconst oldFetch = globalThis.fetch;\n\n\nlet supports: Promise<boolean> | null = null;\n\nasync function checkFetch() {\n try {\n await oldFetch(new URL(\"file:\"));\n return true;\n\n } catch (e) {\n return false;\n }\n}\n\nasync function supportsFetch(): Promise<boolean> {\n if (supports === null) {\n supports = checkFetch();\n }\n\n return await supports;\n}\n\n\n// We always polyfill fetch because Node's fetch doesn't support file URLs.\n(globalThis.fetch as any) = async function (resource: URL | RequestInfo, options: RequestInit | undefined): Promise<Response> {\n const request = new Request(resource, options);\n\n const url = new URL(request.url);\n\n if (!(await supportsFetch()) && url.protocol === \"file:\") {\n const readStream = $fs.createReadStream(url);\n\n const headers: HeadersInit = {};\n\n const type = $mime.getType(url.pathname);\n\n if (type) {\n headers[\"Content-Type\"] = type;\n }\n\n return new Response(readStream as any, {\n status: 200,\n statusText: \"OK\",\n headers,\n });\n\n } else {\n return await oldFetch(request);\n }\n};\n","// @ts-ignore\nimport $xmlhttprequest from \"xmlhttprequest-ssl\";\n\nif (globalThis.XMLHttpRequest == null) {\n (globalThis as any).XMLHttpRequest = class extends $xmlhttprequest.XMLHttpRequest {\n constructor(opts?: any) {\n super({ syncPolicy: \"enabled\", ...opts });\n }\n };\n}","import * as $worker from \"node:worker_threads\";\nimport * as $os from \"node:os\";\n\n// This is technically not a part of the Worker polyfill,\n// but Workers are used for multi-threading, so this is often\n// needed when writing Worker code.\nif (globalThis.navigator == null) {\n globalThis.navigator = {\n hardwareConcurrency: $os.cpus().length,\n } as Navigator;\n}\n\nif (globalThis.Worker == null) {\n globalThis.Worker = class Worker extends EventTarget {\n private _worker: import(\"node:worker_threads\").Worker;\n\n constructor(url: string | URL, options?: WorkerOptions | undefined) {\n super();\n\n if (url instanceof URL) {\n if (url.protocol !== \"file:\") {\n throw new Error(\"Worker only supports file: URLs\");\n }\n\n url = url.href;\n\n } else {\n throw new Error(\"Filepaths are unreliable, use `new URL(\\\"...\\\", import.meta.url)` instead.\");\n }\n\n if (!options || options.type !== \"module\") {\n throw new Error(\"Workers must use \\`type: \\\"module\\\"\\`\");\n }\n\n const code = `\n import(\"node:worker_threads\")\n .then(({ workerData }) => {\n return import(workerData.polyfill)\n .then(() => import(workerData.url))\n })\n .catch((e) => {\n // TODO maybe it should send a message to the parent?\n console.error(e.stack);\n });\n `;\n\n this._worker = new $worker.Worker(code, {\n eval: true,\n workerData: {\n url,\n polyfill: new URL(\"node-polyfill.js\", import.meta.url).href,\n },\n });\n\n this._worker.on(\"message\", (data) => {\n this.dispatchEvent(new MessageEvent(\"message\", { data }));\n });\n\n this._worker.on(\"messageerror\", (error) => {\n throw new Error(\"UNIMPLEMENTED\");\n });\n\n this._worker.on(\"error\", (error) => {\n // TODO attach the error to the event somehow\n const event = new Event(\"error\");\n this.dispatchEvent(event);\n });\n }\n\n set onmessage(f: () => void) {\n throw new Error(\"UNIMPLEMENTED\");\n }\n\n set onmessageerror(f: () => void) {\n throw new Error(\"UNIMPLEMENTED\");\n }\n\n set onerror(f: () => void) {\n throw new Error(\"UNIMPLEMENTED\");\n }\n\n postMessage(message: any, transfer: Array<Transferable>): void;\n postMessage(message: any, options?: StructuredSerializeOptions | undefined): void;\n postMessage(value: any, transfer: any) {\n this._worker.postMessage(value, transfer);\n }\n\n terminate() {\n this._worker.terminate();\n }\n\n // This is Node-specific, it allows the process to exit\n // even if the Worker is still running.\n unref() {\n this._worker.unref();\n }\n };\n}\n\n\nif (!$worker.isMainThread) {\n const globals = globalThis as unknown as DedicatedWorkerGlobalScope;\n\n // This is used to create the onmessage, onmessageerror, and onerror setters\n const makeSetter = (prop: string, event: string) => {\n let oldvalue: () => void;\n\n Object.defineProperty(globals, prop, {\n get() {\n return oldvalue;\n },\n set(value) {\n if (oldvalue) {\n globals.removeEventListener(event, oldvalue);\n }\n\n oldvalue = value;\n\n if (oldvalue) {\n globals.addEventListener(event, oldvalue);\n }\n },\n });\n };\n\n // This makes sure that `f` is only run once\n const memoize = (f: () => void) => {\n let run = false;\n\n return () => {\n if (!run) {\n run = true;\n f();\n }\n };\n };\n\n\n // We only start listening for messages / errors when the worker calls addEventListener\n const startOnMessage = memoize(() => {\n $worker.parentPort!.on(\"message\", (data) => {\n workerEvents.dispatchEvent(new MessageEvent(\"message\", { data }));\n });\n });\n\n const startOnMessageError = memoize(() => {\n throw new Error(\"UNIMPLEMENTED\");\n });\n\n const startOnError = memoize(() => {\n $worker.parentPort!.on(\"error\", (data) => {\n workerEvents.dispatchEvent(new Event(\"error\"));\n });\n });\n\n\n // Node workers don't have top-level events, so we have to make our own\n const workerEvents = new EventTarget();\n\n globals.close = () => {\n process.exit();\n };\n\n globals.addEventListener = (type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined) => {\n workerEvents.addEventListener(type, callback, options);\n\n if (type === \"message\") {\n startOnMessage();\n } else if (type === \"messageerror\") {\n startOnMessageError();\n } else if (type === \"error\") {\n startOnError();\n }\n };\n\n globals.removeEventListener = (type: string, callback: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions | undefined) => {\n workerEvents.removeEventListener(type, callback, options);\n };\n\n function postMessage(message: any, transfer: Transferable[]): void;\n function postMessage(message: any, options?: StructuredSerializeOptions | undefined): void;\n function postMessage(value: any, transfer: any) {\n $worker.parentPort!.postMessage(value, transfer);\n }\n\n globals.postMessage = postMessage;\n\n makeSetter(\"onmessage\", \"message\");\n makeSetter(\"onmessageerror\", \"messageerror\");\n makeSetter(\"onerror\", \"error\");\n}\n","import \"./polyfill/shared.js\";\nimport \"./polyfill/crypto.js\";\nimport \"./polyfill/fetch.js\";\nimport \"./polyfill/xmlhttprequest.js\";\nimport \"./polyfill/worker.js\";\n\nif (!globalThis.self) {\n (globalThis as any).self = globalThis;\n}\n"],"names":[],"mappings":";;;;;;;;AAEA,IAAK,UAAkB,CAAC,MAAM,IAAI,IAAI,EAAE;AACnC,IAAA,UAAk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,IAAI,GAAG,UAAU;AACzC"}
|
package/dist/mainnet/node.d.ts
CHANGED
package/dist/mainnet/node.js
CHANGED
|
@@ -1,13 +1,140 @@
|
|
|
1
1
|
import './node-polyfill.js';
|
|
2
|
-
|
|
2
|
+
import * as fs from 'node:fs/promises';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import { ProvingKey, VerifyingKey } from '@provablehq/wasm/mainnet.js';
|
|
3
5
|
export { Address, Authorization, BHP1024, BHP256, BHP512, BHP768, Boolean, Ciphertext, ComputeKey, 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, ProvingKey, ProvingRequest, RecordCiphertext, RecordPlaintext, Scalar, Signature, Transaction, Transition, U128, U16, U32, U64, U8, VerifyingKey, ViewKey, getOrInitConsensusVersionTestHeights, initThreadPool, verifyFunctionExecution } from '@provablehq/wasm/mainnet.js';
|
|
6
|
+
export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoNetworkClient, BlockHeightSearch, CREDITS_PROGRAM_KEYS, KEY_STORE, 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, RecordScanner, SealanceMerkleTree, VALID_TRANSFER_TYPES, initializeWasm, logAndThrow, promoteMapToKeyStore } from './browser.js';
|
|
4
7
|
import 'core-js/proposals/json-parse-with-source.js';
|
|
5
8
|
import 'node:crypto';
|
|
6
9
|
import 'node:fs';
|
|
7
10
|
import 'mime/lite';
|
|
8
11
|
import 'xmlhttprequest-ssl';
|
|
9
|
-
import 'sync-request';
|
|
10
12
|
import 'node:worker_threads';
|
|
11
13
|
import 'node:os';
|
|
12
14
|
import '@scure/base';
|
|
15
|
+
|
|
16
|
+
class LocalFileKeyStore {
|
|
17
|
+
directory;
|
|
18
|
+
constructor(directory) {
|
|
19
|
+
this.directory = directory ?? path.join(process.cwd(), "keystore");
|
|
20
|
+
// Ensure directory exists
|
|
21
|
+
fs.mkdir(this.directory, { recursive: true }).catch((err) => {
|
|
22
|
+
console.error("Failed to create keystore directory:", err);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
proverPath(locator) {
|
|
26
|
+
return path.join(this.directory, `${locator}.prover`);
|
|
27
|
+
}
|
|
28
|
+
verifierPath(locator) {
|
|
29
|
+
return path.join(this.directory, `${locator}.verifier`);
|
|
30
|
+
}
|
|
31
|
+
async readFileOptional(filepath) {
|
|
32
|
+
try {
|
|
33
|
+
const data = await fs.readFile(filepath);
|
|
34
|
+
return new Uint8Array(data);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
if (err.code === "ENOENT")
|
|
38
|
+
return null;
|
|
39
|
+
throw err;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async writeFileAtomic(filepath, data) {
|
|
43
|
+
// Ensure parent directories for nested locators exist
|
|
44
|
+
await fs.mkdir(path.dirname(filepath), { recursive: true });
|
|
45
|
+
await fs.writeFile(filepath, data);
|
|
46
|
+
}
|
|
47
|
+
async clearRecursive(dir) {
|
|
48
|
+
let entries;
|
|
49
|
+
try {
|
|
50
|
+
entries = await fs.readdir(dir);
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
if (err.code === "ENOENT") {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
throw err;
|
|
57
|
+
}
|
|
58
|
+
await Promise.all(entries.map(async (name) => {
|
|
59
|
+
const full = path.join(dir, name);
|
|
60
|
+
let isDirectory = false;
|
|
61
|
+
try {
|
|
62
|
+
const stat = await fs.stat(full);
|
|
63
|
+
isDirectory = stat.isDirectory();
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (isDirectory) {
|
|
69
|
+
await this.clearRecursive(full);
|
|
70
|
+
}
|
|
71
|
+
else if (name.endsWith(".prover") || name.endsWith(".verifier")) {
|
|
72
|
+
await fs.unlink(full).catch(() => { });
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
// -------------------------------------------------------
|
|
77
|
+
// KEYSTORE INTERFACE
|
|
78
|
+
// -------------------------------------------------------
|
|
79
|
+
async getKeys(locator) {
|
|
80
|
+
const prover = await this.getProvingKey(locator);
|
|
81
|
+
const verifier = await this.getVerifyingKey(locator);
|
|
82
|
+
if (!prover || !verifier)
|
|
83
|
+
return null;
|
|
84
|
+
return [prover, verifier];
|
|
85
|
+
}
|
|
86
|
+
async getKeyBytes(locator) {
|
|
87
|
+
const prover = await this.getProvingKeyBytes(locator);
|
|
88
|
+
const verifier = await this.getVerifyingKeyBytes(locator);
|
|
89
|
+
if (!prover || !verifier)
|
|
90
|
+
return null;
|
|
91
|
+
return [prover, verifier];
|
|
92
|
+
}
|
|
93
|
+
async getProvingKey(locator) {
|
|
94
|
+
const bytes = await this.getProvingKeyBytes(locator);
|
|
95
|
+
return bytes ? ProvingKey.fromBytes(bytes) : null;
|
|
96
|
+
}
|
|
97
|
+
async getProvingKeyBytes(locator) {
|
|
98
|
+
return this.readFileOptional(this.proverPath(locator));
|
|
99
|
+
}
|
|
100
|
+
async getVerifyingKey(locator) {
|
|
101
|
+
const bytes = await this.getVerifyingKeyBytes(locator);
|
|
102
|
+
return bytes ? VerifyingKey.fromBytes(bytes) : null;
|
|
103
|
+
}
|
|
104
|
+
async getVerifyingKeyBytes(locator) {
|
|
105
|
+
return this.readFileOptional(this.verifierPath(locator));
|
|
106
|
+
}
|
|
107
|
+
async setKeys(locator, keys) {
|
|
108
|
+
const [p, v] = keys;
|
|
109
|
+
await this.writeFileAtomic(this.proverPath(locator), p.toBytes());
|
|
110
|
+
await this.writeFileAtomic(this.verifierPath(locator), v.toBytes());
|
|
111
|
+
}
|
|
112
|
+
async setKeyBytes(locator, keys) {
|
|
113
|
+
const [proverBytes, verifierBytes] = keys;
|
|
114
|
+
await this.writeFileAtomic(this.proverPath(locator), proverBytes);
|
|
115
|
+
await this.writeFileAtomic(this.verifierPath(locator), verifierBytes);
|
|
116
|
+
}
|
|
117
|
+
async has(locator) {
|
|
118
|
+
const proverExists = await fs
|
|
119
|
+
.access(this.proverPath(locator))
|
|
120
|
+
.then(() => true)
|
|
121
|
+
.catch(() => false);
|
|
122
|
+
const verifierExists = await fs
|
|
123
|
+
.access(this.verifierPath(locator))
|
|
124
|
+
.then(() => true)
|
|
125
|
+
.catch(() => false);
|
|
126
|
+
return proverExists && verifierExists;
|
|
127
|
+
}
|
|
128
|
+
async delete(locator) {
|
|
129
|
+
const p = this.proverPath(locator);
|
|
130
|
+
const v = this.verifierPath(locator);
|
|
131
|
+
await fs.unlink(p).catch(() => { });
|
|
132
|
+
await fs.unlink(v).catch(() => { });
|
|
133
|
+
}
|
|
134
|
+
async clear() {
|
|
135
|
+
await this.clearRecursive(this.directory);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export { LocalFileKeyStore };
|
|
13
140
|
//# sourceMappingURL=node.js.map
|
package/dist/mainnet/node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"node.js","sources":["../../src/keys/keystore/file.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport * as path from \"path\";\n\nimport { CachedKeyPair, FunctionKeyPair } from \"../../models/keyPair.js\";\nimport { KeyStore } from \"./keystore.js\";\nimport { ProvingKey, VerifyingKey } from \"../../wasm.js\";\n\nexport class LocalFileKeyStore implements KeyStore {\n\n private directory: string;\n\n constructor(directory?: string) {\n this.directory = directory ?? path.join(process.cwd(), \"keystore\");\n\n // Ensure directory exists\n fs.mkdir(this.directory, { recursive: true }).catch((err) => {\n console.error(\"Failed to create keystore directory:\", err);\n });\n }\n\n private proverPath(locator: string): string {\n return path.join(this.directory, `${locator}.prover`);\n }\n\n private verifierPath(locator: string): string {\n return path.join(this.directory, `${locator}.verifier`);\n }\n\n private async readFileOptional(filepath: string): 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 private async writeFileAtomic(filepath: string, data: Uint8Array): Promise<void> {\n // Ensure parent directories for nested locators exist\n await fs.mkdir(path.dirname(filepath), { recursive: true });\n await fs.writeFile(filepath, data);\n }\n\n private async clearRecursive(dir: string): Promise<void> {\n let entries: string[];\n try {\n entries = await fs.readdir(dir);\n } catch (err: any) {\n if (err.code === \"ENOENT\") {\n return;\n }\n throw err;\n }\n\n await Promise.all(entries.map(async (name) => {\n const full = path.join(dir, name);\n let isDirectory = false;\n try {\n const stat = await fs.stat(full);\n isDirectory = stat.isDirectory();\n } catch {\n return;\n }\n\n if (isDirectory) {\n await this.clearRecursive(full);\n } else if (name.endsWith(\".prover\") || name.endsWith(\".verifier\")) {\n await fs.unlink(full).catch(() => {});\n }\n }));\n }\n\n // -------------------------------------------------------\n // KEYSTORE INTERFACE\n // -------------------------------------------------------\n\n async getKeys(locator: string): Promise<FunctionKeyPair | null> {\n const prover = await this.getProvingKey(locator);\n const verifier = await this.getVerifyingKey(locator);\n if (!prover || !verifier) return null;\n return [prover, verifier];\n }\n\n async getKeyBytes(locator: string): Promise<CachedKeyPair | null> {\n const prover = await this.getProvingKeyBytes(locator);\n const verifier = await this.getVerifyingKeyBytes(locator);\n if (!prover || !verifier) return null;\n return [prover, verifier];\n }\n\n async getProvingKey(locator: string): Promise<ProvingKey | null> {\n const bytes = await this.getProvingKeyBytes(locator);\n return bytes ? ProvingKey.fromBytes(bytes) : null;\n }\n\n async getProvingKeyBytes(locator: string): Promise<Uint8Array | null> {\n return this.readFileOptional(this.proverPath(locator));\n }\n\n async getVerifyingKey(locator: string): Promise<VerifyingKey | null> {\n const bytes = await this.getVerifyingKeyBytes(locator);\n return bytes ? VerifyingKey.fromBytes(bytes) : null;\n }\n\n async getVerifyingKeyBytes(locator: string): Promise<Uint8Array | null> {\n return this.readFileOptional(this.verifierPath(locator));\n }\n\n async setKeys(locator: string, keys: FunctionKeyPair): Promise<void> {\n const [p, v] = keys;\n await this.writeFileAtomic(this.proverPath(locator), p.toBytes());\n await this.writeFileAtomic(this.verifierPath(locator), v.toBytes());\n }\n\n async setKeyBytes(locator: string, keys: CachedKeyPair): Promise<void> {\n const [proverBytes, verifierBytes] = keys;\n await this.writeFileAtomic(this.proverPath(locator), proverBytes);\n await this.writeFileAtomic(this.verifierPath(locator), verifierBytes);\n }\n\n async has(locator: string): Promise<boolean> {\n const proverExists = await fs\n .access(this.proverPath(locator))\n .then(() => true)\n .catch(() => false);\n\n const verifierExists = await fs\n .access(this.verifierPath(locator))\n .then(() => true)\n .catch(() => false);\n\n return proverExists && verifierExists;\n }\n\n async delete(locator: string): Promise<void> {\n const p = this.proverPath(locator);\n const v = this.verifierPath(locator);\n\n await fs.unlink(p).catch(() => {});\n await fs.unlink(v).catch(() => {});\n }\n\n async clear(): Promise<void> {\n await this.clearRecursive(this.directory);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;MAOa,iBAAiB,CAAA;AAElB,IAAA,SAAS;AAEjB,IAAA,WAAA,CAAY,SAAkB,EAAA;AAC1B,QAAA,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC;;AAGlE,QAAA,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,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CAAC,EAAE,WAAW,CAAC;AACjE,QAAA,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC;IACzE;IAEA,MAAM,GAAG,CAAC,OAAe,EAAA;QACrB,MAAM,YAAY,GAAG,MAAM;AACtB,aAAA,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;AAC/B,aAAA,IAAI,CAAC,MAAM,IAAI;AACf,aAAA,KAAK,CAAC,MAAM,KAAK,CAAC;QAEvB,MAAM,cAAc,GAAG,MAAM;AACxB,aAAA,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC;AACjC,aAAA,IAAI,CAAC,MAAM,IAAI;AACf,aAAA,KAAK,CAAC,MAAM,KAAK,CAAC;QAEvB,OAAO,YAAY,IAAI,cAAc;IACzC;IAEA,MAAM,MAAM,CAAC,OAAe,EAAA;QACxB,MAAM,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;QAClC,MAAM,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC;AAEpC,QAAA,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAK,EAAE,CAAC,CAAC;AAClC,QAAA,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAK,EAAE,CAAC,CAAC;IACtC;AAEA,IAAA,MAAM,KAAK,GAAA;QACP,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC;IAC7C;AACH;;;;"}
|
|
@@ -3,7 +3,8 @@ import { AleoNetworkClient, AleoNetworkClientOptions, ProgramImports } from "./n
|
|
|
3
3
|
import { ImportedPrograms, ImportedVerifyingKeys } from "./models/imports.js";
|
|
4
4
|
import { RecordProvider } from "./record-provider.js";
|
|
5
5
|
import { RecordSearchParams } from "./models/record-provider/recordSearchParams.js";
|
|
6
|
-
import {
|
|
6
|
+
import { FunctionKeyProvider, KeySearchParams } from "./keys/provider/function-key-provider";
|
|
7
|
+
import { FunctionKeyPair } from "./models/keyPair";
|
|
7
8
|
import { Authorization, ExecutionResponse, OfflineQuery, RecordPlaintext, PrivateKey, Program, ProvingKey, ProvingRequest, VerifyingKey, Transaction } from "./wasm.js";
|
|
8
9
|
/**
|
|
9
10
|
* Represents the options for deploying and upgrading a transaction in the Aleo network.
|
|
@@ -2,6 +2,7 @@ import "./polyfill/shared.js";
|
|
|
2
2
|
import { Account } from "./account.js";
|
|
3
3
|
import { AleoNetworkClient, ProgramImports } from "./network-client.js";
|
|
4
4
|
import { BlockJSON, Header, Metadata } from "./models/blockJSON.js";
|
|
5
|
+
import { CachedKeyPair, FunctionKeyPair } from "./models/keyPair.js";
|
|
5
6
|
import { ConfirmedTransactionJSON } from "./models/confirmed_transaction.js";
|
|
6
7
|
import { DeploymentJSON, VerifyingKeys } from "./models/deployment/deploymentJSON.js";
|
|
7
8
|
import { DeploymentObject } from "./models/deployment/deploymentObject.js";
|
|
@@ -34,8 +35,10 @@ import { TransactionJSON } from "./models/transaction/transactionJSON.js";
|
|
|
34
35
|
import { TransactionObject } from "./models/transaction/transactionObject.js";
|
|
35
36
|
import { TransitionJSON } from "./models/transition/transitionJSON.js";
|
|
36
37
|
import { TransitionObject } from "./models/transition/transitionObject.js";
|
|
37
|
-
import { AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams,
|
|
38
|
-
import {
|
|
38
|
+
import { AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, FunctionKeyProvider, KeySearchParams } from "./keys/provider/function-key-provider";
|
|
39
|
+
import { KeyStore } from "./keys/keystore/keystore";
|
|
40
|
+
import { promoteMapToKeyStore } from "./keys/keystore/memory";
|
|
41
|
+
import { OfflineKeyProvider, OfflineSearchParams } from "./keys/provider/offline-key-provider";
|
|
39
42
|
import { BlockHeightSearch, NetworkRecordProvider, RecordProvider } from "./record-provider.js";
|
|
40
43
|
import { RecordScanner } from "./record-scanner.js";
|
|
41
44
|
import { SealanceMerkleTree } from "./integrations/sealance/merkle-tree.js";
|
|
@@ -45,4 +48,4 @@ export { logAndThrow } from "./utils.js";
|
|
|
45
48
|
export { Address, Authorization, Boolean, BHP256, BHP512, BHP768, BHP1024, Ciphertext, ComputeKey, Execution as FunctionExecution, ExecutionRequest, ExecutionResponse, EncryptionToolkit, Field, GraphKey, Group, I8, I16, I32, I64, I128, OfflineQuery, Pedersen64, Pedersen128, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager as ProgramManagerBase, ProvingKey, ProvingRequest, RecordCiphertext, RecordPlaintext, Signature, Scalar, Transaction, Transition, U8, U16, U32, U64, U128, VerifyingKey, ViewKey, initThreadPool, getOrInitConsensusVersionTestHeights, verifyFunctionExecution, } from "./wasm.js";
|
|
46
49
|
export { initializeWasm };
|
|
47
50
|
export { Key, CREDITS_PROGRAM_KEYS, KEY_STORE, PRIVATE_TRANSFER, PRIVATE_TO_PUBLIC_TRANSFER, PRIVATE_TRANSFER_TYPES, PUBLIC_TRANSFER, PUBLIC_TRANSFER_AS_SIGNER, PUBLIC_TO_PRIVATE_TRANSFER, RECORD_DOMAIN, VALID_TRANSFER_TYPES, } from "./constants.js";
|
|
48
|
-
export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, AleoNetworkClient, BlockJSON, BlockHeightSearch, CachedKeyPair, ConfirmedTransactionJSON, DeploymentJSON, DeploymentObject, EncryptedRecord, ExecutionJSON, ExecutionObject, FeeExecutionJSON, FeeExecutionObject, FinalizeJSON, FunctionInput, FunctionObject, FunctionKeyPair, FunctionKeyProvider, Header, ImportedPrograms, ImportedVerifyingKeys, InputJSON, InputObject, KeySearchParams, Metadata, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, OutputJSON, OutputObject, OwnedFilter, OwnedRecord, OwnerJSON, PartialSolutionJSON, PlaintextArray, PlaintextLiteral, PlaintextObject, PlaintextStruct, ProgramImports, ProvingRequestJSON, ProvingResponse, RatificationJSON, RecordsFilter, RecordsResponseFilter, RecordProvider, RecordScanner, RecordSearchParams, SealanceMerkleTree, SolutionJSON, SolutionsJSON, TransactionJSON, TransactionObject, TransitionJSON, TransitionObject, VerifyingKeys, };
|
|
51
|
+
export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, AleoNetworkClient, BlockJSON, BlockHeightSearch, CachedKeyPair, ConfirmedTransactionJSON, DeploymentJSON, DeploymentObject, EncryptedRecord, ExecutionJSON, ExecutionObject, FeeExecutionJSON, FeeExecutionObject, FinalizeJSON, FunctionInput, FunctionObject, FunctionKeyPair, FunctionKeyProvider, Header, ImportedPrograms, ImportedVerifyingKeys, InputJSON, InputObject, KeyStore, KeySearchParams, Metadata, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, OutputJSON, OutputObject, OwnedFilter, OwnedRecord, OwnerJSON, PartialSolutionJSON, PlaintextArray, PlaintextLiteral, PlaintextObject, PlaintextStruct, ProgramImports, promoteMapToKeyStore, ProvingRequestJSON, ProvingResponse, RatificationJSON, RecordsFilter, RecordsResponseFilter, RecordProvider, RecordScanner, RecordSearchParams, SealanceMerkleTree, SolutionJSON, SolutionsJSON, TransactionJSON, TransactionObject, TransitionJSON, TransitionObject, VerifyingKeys, };
|