@provablehq/sdk 0.6.9
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/README.md +1172 -0
- package/dist/account.d.ts +137 -0
- package/dist/function-key-provider.d.ts +336 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +3049 -0
- package/dist/index.js.map +1 -0
- package/dist/managed-worker.d.ts +3 -0
- package/dist/models/block.d.ts +21 -0
- package/dist/models/confirmed_transaction.d.ts +6 -0
- package/dist/models/execution.d.ts +5 -0
- package/dist/models/input.d.ts +10 -0
- package/dist/models/output.d.ts +6 -0
- package/dist/models/transactionModel.d.ts +6 -0
- package/dist/models/transition.d.ts +13 -0
- package/dist/network-client.d.ts +267 -0
- package/dist/node-polyfill.d.ts +4 -0
- package/dist/node-polyfill.js +302 -0
- package/dist/node-polyfill.js.map +1 -0
- package/dist/node.d.ts +2 -0
- package/dist/node.js +11 -0
- package/dist/node.js.map +1 -0
- package/dist/offline-key-provider.d.ts +347 -0
- package/dist/polyfill/crypto.d.ts +1 -0
- package/dist/polyfill/fetch.d.ts +1 -0
- package/dist/polyfill/worker.d.ts +1 -0
- package/dist/polyfill/xmlhttprequest.d.ts +1 -0
- package/dist/program-manager.d.ts +639 -0
- package/dist/record-provider.d.ts +236 -0
- package/dist/utils.d.ts +2 -0
- package/dist/worker.d.ts +8 -0
- package/dist/worker.js +74 -0
- package/dist/worker.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { Address, PrivateKey, Signature, ViewKey, PrivateKeyCiphertext, RecordCiphertext } from "./index";
|
|
2
|
+
interface AccountParam {
|
|
3
|
+
privateKey?: string;
|
|
4
|
+
seed?: Uint8Array;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Key Management class. Enables the creation of a new Aleo Account, importation of an existing account from
|
|
8
|
+
* an existing private key or seed, and message signing and verification functionality.
|
|
9
|
+
*
|
|
10
|
+
* An Aleo Account is generated from a randomly generated seed (number) from which an account private key, view key,
|
|
11
|
+
* and a public account address are derived. The private key lies at the root of an Aleo account. It is a highly
|
|
12
|
+
* sensitive secret and should be protected as it allows for creation of Aleo Program executions and arbitrary value
|
|
13
|
+
* transfers. The View Key allows for decryption of a user's activity on the blockchain. The Address is the public
|
|
14
|
+
* address to which other users of Aleo can send Aleo credits and other records to. This class should only be used
|
|
15
|
+
* environments where the safety of the underlying key material can be assured.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // Create a new account
|
|
19
|
+
* const myRandomAccount = new Account();
|
|
20
|
+
*
|
|
21
|
+
* // Create an account from a randomly generated seed
|
|
22
|
+
* const seed = new Uint8Array([94, 91, 52, 251, 240, 230, 226, 35, 117, 253, 224, 210, 175, 13, 205, 120, 155, 214, 7, 169, 66, 62, 206, 50, 188, 40, 29, 122, 40, 250, 54, 18]);
|
|
23
|
+
* const mySeededAccount = new Account({seed: seed});
|
|
24
|
+
*
|
|
25
|
+
* // Create an account from an existing private key
|
|
26
|
+
* const myExistingAccount = new Account({privateKey: 'myExistingPrivateKey'})
|
|
27
|
+
*
|
|
28
|
+
* // Sign a message
|
|
29
|
+
* const hello_world = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
|
|
30
|
+
* const signature = myRandomAccount.sign(hello_world)
|
|
31
|
+
*
|
|
32
|
+
* // Verify a signature
|
|
33
|
+
* myRandomAccount.verify(hello_world, signature)
|
|
34
|
+
*/
|
|
35
|
+
export declare class Account {
|
|
36
|
+
_privateKey: PrivateKey;
|
|
37
|
+
_viewKey: ViewKey;
|
|
38
|
+
_address: Address;
|
|
39
|
+
constructor(params?: AccountParam);
|
|
40
|
+
/**
|
|
41
|
+
* Attempts to create an account from a private key ciphertext
|
|
42
|
+
* @param {PrivateKeyCiphertext | string} ciphertext
|
|
43
|
+
* @param {string} password
|
|
44
|
+
* @returns {PrivateKey | Error}
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const ciphertext = PrivateKey.newEncrypted("password");
|
|
48
|
+
* const account = Account.fromCiphertext(ciphertext, "password");
|
|
49
|
+
*/
|
|
50
|
+
static fromCiphertext(ciphertext: PrivateKeyCiphertext | string, password: string): Account;
|
|
51
|
+
private privateKeyFromParams;
|
|
52
|
+
privateKey(): PrivateKey;
|
|
53
|
+
viewKey(): ViewKey;
|
|
54
|
+
address(): Address;
|
|
55
|
+
toString(): string;
|
|
56
|
+
/**
|
|
57
|
+
* Encrypt the account's private key with a password
|
|
58
|
+
* @param {string} ciphertext
|
|
59
|
+
* @returns {PrivateKeyCiphertext}
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* const account = new Account();
|
|
63
|
+
* const ciphertext = account.encryptAccount("password");
|
|
64
|
+
*/
|
|
65
|
+
encryptAccount(password: string): PrivateKeyCiphertext;
|
|
66
|
+
/**
|
|
67
|
+
* Decrypts a Record in ciphertext form into plaintext
|
|
68
|
+
* @param {string} ciphertext
|
|
69
|
+
* @returns {Record}
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* const account = new Account();
|
|
73
|
+
* const record = account.decryptRecord("record1ciphertext");
|
|
74
|
+
*/
|
|
75
|
+
decryptRecord(ciphertext: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* Decrypts an array of Records in ciphertext form into plaintext
|
|
78
|
+
* @param {string[]} ciphertexts
|
|
79
|
+
* @returns {Record[]}
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* const account = new Account();
|
|
83
|
+
* const record = account.decryptRecords(["record1ciphertext", "record2ciphertext"]);
|
|
84
|
+
*/
|
|
85
|
+
decryptRecords(ciphertexts: string[]): string[];
|
|
86
|
+
/**
|
|
87
|
+
* Determines whether the account owns a ciphertext record
|
|
88
|
+
* @param {RecordCipherText | string} ciphertext
|
|
89
|
+
* @returns {boolean}
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* // Create a connection to the Aleo network and an account
|
|
93
|
+
* const connection = new NodeConnection("vm.aleo.org/api");
|
|
94
|
+
* const account = Account.fromCiphertext("ciphertext", "password");
|
|
95
|
+
*
|
|
96
|
+
* // Get a record from the network
|
|
97
|
+
* const record = connection.getBlock(1234);
|
|
98
|
+
* const recordCipherText = record.transactions[0].execution.transitions[0].id;
|
|
99
|
+
*
|
|
100
|
+
* // Check if the account owns the record
|
|
101
|
+
* if account.ownsRecord(recordCipherText) {
|
|
102
|
+
* // Then one can do something like:
|
|
103
|
+
* // Decrypt the record and check if it's spent
|
|
104
|
+
* // Store the record in a local database
|
|
105
|
+
* // Etc.
|
|
106
|
+
* }
|
|
107
|
+
*/
|
|
108
|
+
ownsRecordCiphertext(ciphertext: RecordCiphertext | string): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Signs a message with the account's private key.
|
|
111
|
+
* Returns a Signature.
|
|
112
|
+
*
|
|
113
|
+
* @param {Uint8Array} message
|
|
114
|
+
* @returns {Signature}
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* const account = new Account();
|
|
118
|
+
* const message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
|
|
119
|
+
* account.sign(message);
|
|
120
|
+
*/
|
|
121
|
+
sign(message: Uint8Array): Signature;
|
|
122
|
+
/**
|
|
123
|
+
* Verifies the Signature on a message.
|
|
124
|
+
*
|
|
125
|
+
* @param {Uint8Array} message
|
|
126
|
+
* @param {Signature} signature
|
|
127
|
+
* @returns {boolean}
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* const account = new Account();
|
|
131
|
+
* const message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
|
|
132
|
+
* const signature = account.sign(message);
|
|
133
|
+
* account.verify(message, signature);
|
|
134
|
+
*/
|
|
135
|
+
verify(message: Uint8Array, signature: Signature): boolean;
|
|
136
|
+
}
|
|
137
|
+
export {};
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { ProvingKey, VerifyingKey } from "./index";
|
|
2
|
+
type FunctionKeyPair = [ProvingKey, VerifyingKey];
|
|
3
|
+
type CachedKeyPair = [Uint8Array, Uint8Array];
|
|
4
|
+
type AleoKeyProviderInitParams = {
|
|
5
|
+
proverUri?: string;
|
|
6
|
+
verifierUri?: string;
|
|
7
|
+
cacheKey?: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Interface for record search parameters. This allows for arbitrary search parameters to be passed to record provider
|
|
11
|
+
* implementations.
|
|
12
|
+
*/
|
|
13
|
+
interface KeySearchParams {
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* AleoKeyProviderParams search parameter for the AleoKeyProvider. It allows for the specification of a proverUri and
|
|
18
|
+
* verifierUri to fetch keys via HTTP from a remote resource as well as a unique cacheKey to store the keys in memory.
|
|
19
|
+
*/
|
|
20
|
+
declare class AleoKeyProviderParams implements KeySearchParams {
|
|
21
|
+
proverUri: string | undefined;
|
|
22
|
+
verifierUri: string | undefined;
|
|
23
|
+
cacheKey: string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Create a new AleoKeyProviderParams object which implements the KeySearchParams interface. Users can optionally
|
|
26
|
+
* specify a url for the proverUri & verifierUri to fetch keys via HTTP from a remote resource as well as a unique
|
|
27
|
+
* cacheKey to store the keys in memory for future use. If no proverUri or verifierUri is specified, a cachekey must
|
|
28
|
+
* be provided.
|
|
29
|
+
*
|
|
30
|
+
* @param { AleoKeyProviderInitParams } params - Optional search parameters
|
|
31
|
+
*/
|
|
32
|
+
constructor(params: {
|
|
33
|
+
proverUri?: string;
|
|
34
|
+
verifierUri?: string;
|
|
35
|
+
cacheKey?: string;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* KeyProvider interface. Enables the retrieval of public proving and verifying keys for Aleo Programs.
|
|
40
|
+
*/
|
|
41
|
+
interface FunctionKeyProvider {
|
|
42
|
+
/**
|
|
43
|
+
* Get bond_public function keys from the credits.aleo program
|
|
44
|
+
*
|
|
45
|
+
* @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the bond_public function
|
|
46
|
+
*/
|
|
47
|
+
bondPublicKeys(): Promise<FunctionKeyPair | Error>;
|
|
48
|
+
/**
|
|
49
|
+
* Get bond_validator function keys from the credits.aleo program
|
|
50
|
+
*
|
|
51
|
+
* @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the bond_validator function
|
|
52
|
+
*/
|
|
53
|
+
bondValidatorKeys(): Promise<FunctionKeyPair | Error>;
|
|
54
|
+
/**
|
|
55
|
+
* Cache a set of keys. This will overwrite any existing keys with the same keyId. The user can check if a keyId
|
|
56
|
+
* exists in the cache using the containsKeys method prior to calling this method if overwriting is not desired.
|
|
57
|
+
*
|
|
58
|
+
* @param {string} keyId access key for the cache
|
|
59
|
+
* @param {FunctionKeyPair} keys keys to cache
|
|
60
|
+
*/
|
|
61
|
+
cacheKeys(keyId: string, keys: FunctionKeyPair): void;
|
|
62
|
+
/**
|
|
63
|
+
* Get unbond_public function keys from the credits.aleo program
|
|
64
|
+
*
|
|
65
|
+
* @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the unbond_public function
|
|
66
|
+
*/
|
|
67
|
+
claimUnbondPublicKeys(): Promise<FunctionKeyPair | Error>;
|
|
68
|
+
/**
|
|
69
|
+
* Get arbitrary function keys from a provider
|
|
70
|
+
*
|
|
71
|
+
* @param {KeySearchParams | undefined} params - Optional search parameters for the key provider
|
|
72
|
+
* @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the specified program
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* // Create a search object which implements the KeySearchParams interface
|
|
76
|
+
* class IndexDbSearch implements KeySearchParams {
|
|
77
|
+
* db: string
|
|
78
|
+
* keyId: string
|
|
79
|
+
* constructor(params: {db: string, keyId: string}) {
|
|
80
|
+
* this.db = params.db;
|
|
81
|
+
* this.keyId = params.keyId;
|
|
82
|
+
* }
|
|
83
|
+
* }
|
|
84
|
+
*
|
|
85
|
+
* // Create a new object which implements the KeyProvider interface
|
|
86
|
+
* class IndexDbKeyProvider implements FunctionKeyProvider {
|
|
87
|
+
* async functionKeys(params: KeySearchParams): Promise<FunctionKeyPair | Error> {
|
|
88
|
+
* return new Promise((resolve, reject) => {
|
|
89
|
+
* const request = indexedDB.open(params.db, 1);
|
|
90
|
+
*
|
|
91
|
+
* request.onupgradeneeded = function(e) {
|
|
92
|
+
* const db = e.target.result;
|
|
93
|
+
* if (!db.objectStoreNames.contains('keys')) {
|
|
94
|
+
* db.createObjectStore('keys', { keyPath: 'id' });
|
|
95
|
+
* }
|
|
96
|
+
* };
|
|
97
|
+
*
|
|
98
|
+
* request.onsuccess = function(e) {
|
|
99
|
+
* const db = e.target.result;
|
|
100
|
+
* const transaction = db.transaction(["keys"], "readonly");
|
|
101
|
+
* const store = transaction.objectStore("keys");
|
|
102
|
+
* const request = store.get(params.keyId);
|
|
103
|
+
* request.onsuccess = function(e) {
|
|
104
|
+
* if (request.result) {
|
|
105
|
+
* resolve(request.result as FunctionKeyPair);
|
|
106
|
+
* } else {
|
|
107
|
+
* reject(new Error("Key not found"));
|
|
108
|
+
* }
|
|
109
|
+
* };
|
|
110
|
+
* request.onerror = function(e) { reject(new Error("Error fetching key")); };
|
|
111
|
+
* };
|
|
112
|
+
*
|
|
113
|
+
* request.onerror = function(e) { reject(new Error("Error opening database")); };
|
|
114
|
+
* });
|
|
115
|
+
* }
|
|
116
|
+
*
|
|
117
|
+
* // implement the other methods...
|
|
118
|
+
* }
|
|
119
|
+
*
|
|
120
|
+
*
|
|
121
|
+
* const keyProvider = new AleoKeyProvider();
|
|
122
|
+
* const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
|
|
123
|
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
124
|
+
*
|
|
125
|
+
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
126
|
+
* const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
|
|
127
|
+
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
128
|
+
*
|
|
129
|
+
* // Keys can also be fetched manually
|
|
130
|
+
* const searchParams = new IndexDbSearch({db: "keys", keyId: "credits.aleo:transferPrivate"});
|
|
131
|
+
* const [transferPrivateProvingKey, transferPrivateVerifyingKey] = await keyProvider.functionKeys(searchParams);
|
|
132
|
+
*/
|
|
133
|
+
functionKeys(params?: KeySearchParams): Promise<FunctionKeyPair | Error>;
|
|
134
|
+
/**
|
|
135
|
+
* Get fee_private function keys from the credits.aleo program
|
|
136
|
+
*
|
|
137
|
+
* @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the join function
|
|
138
|
+
*/
|
|
139
|
+
feePrivateKeys(): Promise<FunctionKeyPair | Error>;
|
|
140
|
+
/**
|
|
141
|
+
* Get fee_public function keys from the credits.aleo program
|
|
142
|
+
*
|
|
143
|
+
* @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the join function
|
|
144
|
+
*/
|
|
145
|
+
feePublicKeys(): Promise<FunctionKeyPair | Error>;
|
|
146
|
+
/**
|
|
147
|
+
* Get join function keys from the credits.aleo program
|
|
148
|
+
*
|
|
149
|
+
* @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the join function
|
|
150
|
+
*/
|
|
151
|
+
joinKeys(): Promise<FunctionKeyPair | Error>;
|
|
152
|
+
/**
|
|
153
|
+
* Get split function keys from the credits.aleo program
|
|
154
|
+
*
|
|
155
|
+
* @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the join function
|
|
156
|
+
*/
|
|
157
|
+
splitKeys(): Promise<FunctionKeyPair | Error>;
|
|
158
|
+
/**
|
|
159
|
+
* Get keys for a variant of the transfer function from the credits.aleo program
|
|
160
|
+
*
|
|
161
|
+
* @param {string} visibility Visibility of the transfer function (private, public, privateToPublic, publicToPrivate)
|
|
162
|
+
* @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the specified transfer function
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* // Create a new object which implements the KeyProvider interface
|
|
166
|
+
* const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
|
|
167
|
+
* const keyProvider = new AleoKeyProvider();
|
|
168
|
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
169
|
+
*
|
|
170
|
+
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
171
|
+
* const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
|
|
172
|
+
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
173
|
+
*
|
|
174
|
+
* // Keys can also be fetched manually
|
|
175
|
+
* const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider.transferKeys("public");
|
|
176
|
+
*/
|
|
177
|
+
transferKeys(visibility: string): Promise<FunctionKeyPair | Error>;
|
|
178
|
+
/**
|
|
179
|
+
* Get unbond_public function keys from the credits.aleo program
|
|
180
|
+
*
|
|
181
|
+
* @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the join function
|
|
182
|
+
*/
|
|
183
|
+
unBondPublicKeys(): Promise<FunctionKeyPair | Error>;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* AleoKeyProvider class. Implements the KeyProvider interface. Enables the retrieval of Aleo program proving and
|
|
187
|
+
* verifying keys for the credits.aleo program over http from official Aleo sources and storing and retrieving function
|
|
188
|
+
* keys from a local memory cache.
|
|
189
|
+
*/
|
|
190
|
+
declare class AleoKeyProvider implements FunctionKeyProvider {
|
|
191
|
+
cache: Map<string, CachedKeyPair>;
|
|
192
|
+
cacheOption: boolean;
|
|
193
|
+
keyUris: string;
|
|
194
|
+
fetchBytes(url?: string): Promise<Uint8Array>;
|
|
195
|
+
constructor();
|
|
196
|
+
/**
|
|
197
|
+
* Use local memory to store keys
|
|
198
|
+
*
|
|
199
|
+
* @param {boolean} useCache whether to store keys in local memory
|
|
200
|
+
*/
|
|
201
|
+
useCache(useCache: boolean): void;
|
|
202
|
+
/**
|
|
203
|
+
* Clear the key cache
|
|
204
|
+
*/
|
|
205
|
+
clearCache(): void;
|
|
206
|
+
/**
|
|
207
|
+
* Cache a set of keys. This will overwrite any existing keys with the same keyId. The user can check if a keyId
|
|
208
|
+
* exists in the cache using the containsKeys method prior to calling this method if overwriting is not desired.
|
|
209
|
+
*
|
|
210
|
+
* @param {string} keyId access key for the cache
|
|
211
|
+
* @param {FunctionKeyPair} keys keys to cache
|
|
212
|
+
*/
|
|
213
|
+
cacheKeys(keyId: string, keys: FunctionKeyPair): void;
|
|
214
|
+
/**
|
|
215
|
+
* Determine if a keyId exists in the cache
|
|
216
|
+
*
|
|
217
|
+
* @param {string} keyId keyId of a proving and verifying key pair
|
|
218
|
+
* @returns {boolean} true if the keyId exists in the cache, false otherwise
|
|
219
|
+
*/
|
|
220
|
+
containsKeys(keyId: string): boolean;
|
|
221
|
+
/**
|
|
222
|
+
* Delete a set of keys from the cache
|
|
223
|
+
*
|
|
224
|
+
* @param {string} keyId keyId of a proving and verifying key pair to delete from memory
|
|
225
|
+
* @returns {boolean} true if the keyId exists in the cache and was deleted, false if the key did not exist
|
|
226
|
+
*/
|
|
227
|
+
deleteKeys(keyId: string): boolean;
|
|
228
|
+
/**
|
|
229
|
+
* Get a set of keys from the cache
|
|
230
|
+
* @param keyId keyId of a proving and verifying key pair
|
|
231
|
+
*
|
|
232
|
+
* @returns {FunctionKeyPair | Error} Proving and verifying keys for the specified program
|
|
233
|
+
*/
|
|
234
|
+
getKeys(keyId: string): FunctionKeyPair | Error;
|
|
235
|
+
/**
|
|
236
|
+
* Get arbitrary function keys from a provider
|
|
237
|
+
*
|
|
238
|
+
* @param {KeySearchParams} params parameters for the key search in form of: {proverUri: string, verifierUri: string, cacheKey: string}
|
|
239
|
+
* @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the specified program
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* // Create a new object which implements the KeyProvider interface
|
|
243
|
+
* const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
|
|
244
|
+
* const keyProvider = new AleoKeyProvider();
|
|
245
|
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
246
|
+
*
|
|
247
|
+
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
248
|
+
* const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
|
|
249
|
+
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
250
|
+
*
|
|
251
|
+
* // Keys can also be fetched manually using the key provider
|
|
252
|
+
* const keySearchParams = { "cacheKey": "myProgram:myFunction" };
|
|
253
|
+
* const [transferPrivateProvingKey, transferPrivateVerifyingKey] = await keyProvider.functionKeys(keySearchParams);
|
|
254
|
+
*/
|
|
255
|
+
functionKeys(params?: KeySearchParams): Promise<FunctionKeyPair | Error>;
|
|
256
|
+
/**
|
|
257
|
+
* Returns the proving and verifying keys for a specified program from a specified url.
|
|
258
|
+
*
|
|
259
|
+
* @param {string} verifierUrl Url of the proving key
|
|
260
|
+
* @param {string} proverUrl Url the verifying key
|
|
261
|
+
* @param {string} cacheKey Key to store the keys in the cache
|
|
262
|
+
*
|
|
263
|
+
* @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the specified program
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* // Create a new AleoKeyProvider object
|
|
267
|
+
* const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
|
|
268
|
+
* const keyProvider = new AleoKeyProvider();
|
|
269
|
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
270
|
+
*
|
|
271
|
+
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
272
|
+
* const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
|
|
273
|
+
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
274
|
+
*
|
|
275
|
+
* // Keys can also be fetched manually
|
|
276
|
+
* const [transferPrivateProvingKey, transferPrivateVerifyingKey] = await keyProvider.fetchKeys(
|
|
277
|
+
* CREDITS_PROGRAM_KEYS.transfer_private.prover,
|
|
278
|
+
* CREDITS_PROGRAM_KEYS.transfer_private.verifier,
|
|
279
|
+
* );
|
|
280
|
+
*/
|
|
281
|
+
fetchKeys(proverUrl: string, verifierUrl: string, cacheKey?: string): Promise<FunctionKeyPair | Error>;
|
|
282
|
+
bondPublicKeys(): Promise<FunctionKeyPair | Error>;
|
|
283
|
+
bondValidatorKeys(): Promise<FunctionKeyPair | Error>;
|
|
284
|
+
claimUnbondPublicKeys(): Promise<FunctionKeyPair | Error>;
|
|
285
|
+
/**
|
|
286
|
+
* Returns the proving and verifying keys for the transfer functions in the credits.aleo program
|
|
287
|
+
* @param {string} visibility Visibility of the transfer function
|
|
288
|
+
* @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the transfer functions
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* // Create a new AleoKeyProvider
|
|
292
|
+
* const networkClient = new AleoNetworkClient("https://api.explorer.aleo.org/v1");
|
|
293
|
+
* const keyProvider = new AleoKeyProvider();
|
|
294
|
+
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
295
|
+
*
|
|
296
|
+
* // Initialize a program manager with the key provider to automatically fetch keys for value transfers
|
|
297
|
+
* const programManager = new ProgramManager("https://api.explorer.aleo.org/v1", keyProvider, recordProvider);
|
|
298
|
+
* programManager.transfer(1, "aleo166q6ww6688cug7qxwe7nhctjpymydwzy2h7rscfmatqmfwnjvggqcad0at", "public", 0.5);
|
|
299
|
+
*
|
|
300
|
+
* // Keys can also be fetched manually
|
|
301
|
+
* const [transferPublicProvingKey, transferPublicVerifyingKey] = await keyProvider.transferKeys("public");
|
|
302
|
+
*/
|
|
303
|
+
transferKeys(visibility: string): Promise<FunctionKeyPair | Error>;
|
|
304
|
+
/**
|
|
305
|
+
* Returns the proving and verifying keys for the join function in the credits.aleo program
|
|
306
|
+
*
|
|
307
|
+
* @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the join function
|
|
308
|
+
*/
|
|
309
|
+
joinKeys(): Promise<FunctionKeyPair | Error>;
|
|
310
|
+
/**
|
|
311
|
+
* Returns the proving and verifying keys for the split function in the credits.aleo program
|
|
312
|
+
*
|
|
313
|
+
* @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the split function
|
|
314
|
+
* */
|
|
315
|
+
splitKeys(): Promise<FunctionKeyPair | Error>;
|
|
316
|
+
/**
|
|
317
|
+
* Returns the proving and verifying keys for the fee_private function in the credits.aleo program
|
|
318
|
+
*
|
|
319
|
+
* @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the fee function
|
|
320
|
+
*/
|
|
321
|
+
feePrivateKeys(): Promise<FunctionKeyPair | Error>;
|
|
322
|
+
/**
|
|
323
|
+
* Returns the proving and verifying keys for the fee_public function in the credits.aleo program
|
|
324
|
+
*
|
|
325
|
+
* @returns {Promise<FunctionKeyPair | Error>} Proving and verifying keys for the fee function
|
|
326
|
+
*/
|
|
327
|
+
feePublicKeys(): Promise<FunctionKeyPair | Error>;
|
|
328
|
+
/**
|
|
329
|
+
* Gets a verifying key. If the verifying key is for a credits.aleo function, get it from the wasm cache otherwise
|
|
330
|
+
*
|
|
331
|
+
* @returns {Promise<VerifyingKey | Error>} Verifying key for the function
|
|
332
|
+
*/
|
|
333
|
+
getVerifyingKey(verifierUri: string): Promise<VerifyingKey | Error>;
|
|
334
|
+
unBondPublicKeys(): Promise<FunctionKeyPair | Error>;
|
|
335
|
+
}
|
|
336
|
+
export { AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, CachedKeyPair, FunctionKeyPair, FunctionKeyProvider, KeySearchParams };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { VerifyingKey } from "@provablehq/wasm";
|
|
2
|
+
declare const KEY_STORE: string;
|
|
3
|
+
interface Key {
|
|
4
|
+
locator: string;
|
|
5
|
+
prover: string;
|
|
6
|
+
verifier: string;
|
|
7
|
+
verifyingKey: () => VerifyingKey;
|
|
8
|
+
}
|
|
9
|
+
declare const CREDITS_PROGRAM_KEYS: {
|
|
10
|
+
bond_public: Key;
|
|
11
|
+
bond_validator: Key;
|
|
12
|
+
claim_unbond_public: Key;
|
|
13
|
+
fee_private: Key;
|
|
14
|
+
fee_public: Key;
|
|
15
|
+
inclusion: Key;
|
|
16
|
+
join: Key;
|
|
17
|
+
set_validator_state: Key;
|
|
18
|
+
split: Key;
|
|
19
|
+
transfer_private: Key;
|
|
20
|
+
transfer_private_to_public: Key;
|
|
21
|
+
transfer_public: Key;
|
|
22
|
+
transfer_public_as_signer: Key;
|
|
23
|
+
transfer_public_to_private: Key;
|
|
24
|
+
unbond_public: Key;
|
|
25
|
+
};
|
|
26
|
+
declare const PRIVATE_TRANSFER_TYPES: Set<string>;
|
|
27
|
+
declare const VALID_TRANSFER_TYPES: Set<string>;
|
|
28
|
+
declare const PRIVATE_TRANSFER: Set<string>;
|
|
29
|
+
declare const PRIVATE_TO_PUBLIC_TRANSFER: Set<string>;
|
|
30
|
+
declare const PUBLIC_TRANSFER: Set<string>;
|
|
31
|
+
declare const PUBLIC_TRANSFER_AS_SIGNER: Set<string>;
|
|
32
|
+
declare const PUBLIC_TO_PRIVATE_TRANSFER: Set<string>;
|
|
33
|
+
declare function logAndThrow(message: string): Error;
|
|
34
|
+
import { Account } from "./account";
|
|
35
|
+
import { AleoNetworkClient, ProgramImports } from "./network-client";
|
|
36
|
+
import { Block } from "./models/block";
|
|
37
|
+
import { Execution } from "./models/execution";
|
|
38
|
+
import { Input } from "./models/input";
|
|
39
|
+
import { Output } from "./models/output";
|
|
40
|
+
import { TransactionModel } from "./models/transactionModel";
|
|
41
|
+
import { Transition } from "./models/transition";
|
|
42
|
+
import { AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, CachedKeyPair, FunctionKeyPair, FunctionKeyProvider, KeySearchParams } from "./function-key-provider";
|
|
43
|
+
import { OfflineKeyProvider, OfflineSearchParams } from "./offline-key-provider";
|
|
44
|
+
import { BlockHeightSearch, NetworkRecordProvider, RecordProvider, RecordSearchParams } from "./record-provider";
|
|
45
|
+
declare function initializeWasm(): Promise<void>;
|
|
46
|
+
export { createAleoWorker } from "./managed-worker";
|
|
47
|
+
export { ProgramManager } from "./program-manager";
|
|
48
|
+
export { Address, Execution as FunctionExecution, ExecutionResponse, Field, OfflineQuery, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager as ProgramManagerBase, ProvingKey, RecordCiphertext, RecordPlaintext, Signature, Transaction, VerifyingKey, ViewKey, initThreadPool, verifyFunctionExecution, } from "@provablehq/wasm";
|
|
49
|
+
export { initializeWasm };
|
|
50
|
+
export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, AleoNetworkClient, Block, BlockHeightSearch, CachedKeyPair, Execution, FunctionKeyPair, FunctionKeyProvider, Input, KeySearchParams, NetworkRecordProvider, ProgramImports, OfflineKeyProvider, OfflineSearchParams, Output, RecordProvider, RecordSearchParams, TransactionModel, Transition, CREDITS_PROGRAM_KEYS, KEY_STORE, PRIVATE_TRANSFER, PRIVATE_TO_PUBLIC_TRANSFER, PRIVATE_TRANSFER_TYPES, PUBLIC_TRANSFER, PUBLIC_TRANSFER_AS_SIGNER, PUBLIC_TO_PRIVATE_TRANSFER, VALID_TRANSFER_TYPES, logAndThrow, };
|