@provablehq/sdk 0.8.7 → 0.9.0
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/account.d.ts +176 -59
- package/dist/mainnet/browser.d.ts +2 -1
- package/dist/mainnet/browser.js +170 -53
- package/dist/mainnet/browser.js.map +1 -1
- package/dist/mainnet/models/imports.d.ts +7 -0
- package/dist/mainnet/network-client.d.ts +340 -65
- package/dist/mainnet/node.js +1 -1
- package/dist/mainnet/{program-manager-D0WpABBc.js → program-manager-C1m8QHkg.js} +817 -221
- package/dist/mainnet/program-manager-C1m8QHkg.js.map +1 -0
- package/dist/mainnet/program-manager.d.ts +88 -31
- package/dist/mainnet/utils.d.ts +9 -0
- package/dist/mainnet/worker.js +1 -1
- package/dist/testnet/account.d.ts +176 -59
- package/dist/testnet/browser.d.ts +2 -1
- package/dist/testnet/browser.js +170 -53
- package/dist/testnet/browser.js.map +1 -1
- package/dist/testnet/models/imports.d.ts +7 -0
- package/dist/testnet/network-client.d.ts +340 -65
- package/dist/testnet/node.js +1 -1
- package/dist/testnet/{program-manager-CVoUpH8X.js → program-manager-Dx4UkssS.js} +817 -221
- package/dist/testnet/program-manager-Dx4UkssS.js.map +1 -0
- package/dist/testnet/program-manager.d.ts +88 -31
- package/dist/testnet/utils.d.ts +9 -0
- package/dist/testnet/worker.js +1 -1
- package/package.json +2 -2
- package/dist/mainnet/program-manager-D0WpABBc.js.map +0 -1
- package/dist/testnet/program-manager-CVoUpH8X.js.map +0 -1
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { Address, ComputeKey, PrivateKey, Signature, ViewKey, PrivateKeyCiphertext, RecordCiphertext } from "./wasm";
|
|
1
|
+
import { Address, ComputeKey, PrivateKey, Signature, ViewKey, PrivateKeyCiphertext, RecordCiphertext, RecordPlaintext } from "./wasm";
|
|
2
2
|
interface AccountParam {
|
|
3
3
|
privateKey?: string;
|
|
4
4
|
seed?: Uint8Array;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
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
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* environments where the safety of the underlying key material can be assured.
|
|
8
|
+
* an existing private key or seed, and message signing and verification functionality. An Aleo Account is generated
|
|
9
|
+
* from a randomly generated seed (number) from which an account private key, view key, and a public account address are
|
|
10
|
+
* derived. The private key lies at the root of an Aleo account. It is a highly sensitive secret and should be protected
|
|
11
|
+
* as it allows for creation of Aleo Program executions and arbitrary value transfers. The View Key allows for decryption
|
|
12
|
+
* of a user's activity on the blockchain. The Address is the public address to which other users of Aleo can send Aleo
|
|
13
|
+
* credits and other records to. This class should only be used in environments where the safety of the underlying key
|
|
14
|
+
* material can be assured.
|
|
16
15
|
*
|
|
17
16
|
* @example
|
|
17
|
+
* import { Account } from "@provablehq/sdk/testnet.js";
|
|
18
|
+
*
|
|
18
19
|
* // Create a new account
|
|
19
20
|
* const myRandomAccount = new Account();
|
|
20
21
|
*
|
|
@@ -23,14 +24,14 @@ interface AccountParam {
|
|
|
23
24
|
* const mySeededAccount = new Account({seed: seed});
|
|
24
25
|
*
|
|
25
26
|
* // Create an account from an existing private key
|
|
26
|
-
* const myExistingAccount = new Account({privateKey:
|
|
27
|
+
* const myExistingAccount = new Account({privateKey: process.env.privateKey});
|
|
27
28
|
*
|
|
28
29
|
* // 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)
|
|
30
|
+
* const hello_world = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100]);
|
|
31
|
+
* const signature = myRandomAccount.sign(hello_world);
|
|
31
32
|
*
|
|
32
33
|
* // Verify a signature
|
|
33
|
-
* myRandomAccount.verify(hello_world, signature)
|
|
34
|
+
* assert(myRandomAccount.verify(hello_world, signature));
|
|
34
35
|
*/
|
|
35
36
|
export declare class Account {
|
|
36
37
|
_privateKey: PrivateKey;
|
|
@@ -40,101 +41,217 @@ export declare class Account {
|
|
|
40
41
|
constructor(params?: AccountParam);
|
|
41
42
|
/**
|
|
42
43
|
* Attempts to create an account from a private key ciphertext
|
|
43
|
-
* @param {PrivateKeyCiphertext | string} ciphertext
|
|
44
|
-
* @param {string} password
|
|
45
|
-
* @returns {
|
|
44
|
+
* @param {PrivateKeyCiphertext | string} ciphertext The encrypted private key ciphertext or its string representation
|
|
45
|
+
* @param {string} password The password used to decrypt the private key ciphertext
|
|
46
|
+
* @returns {Account} A new Account instance created from the decrypted private key
|
|
46
47
|
*
|
|
47
48
|
* @example
|
|
48
|
-
*
|
|
49
|
+
* import { Account } from "@provablehq/sdk/testnet.js";
|
|
50
|
+
*
|
|
51
|
+
* // Create an account object from a previously encrypted ciphertext and password.
|
|
49
52
|
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
50
53
|
*/
|
|
51
54
|
static fromCiphertext(ciphertext: PrivateKeyCiphertext | string, password: string): Account;
|
|
55
|
+
/**
|
|
56
|
+
* Creates a PrivateKey from the provided parameters.
|
|
57
|
+
* @param {AccountParam} params The parameters containing either a private key string or a seed
|
|
58
|
+
* @returns {PrivateKey} A PrivateKey instance derived from the provided parameters
|
|
59
|
+
*/
|
|
52
60
|
private privateKeyFromParams;
|
|
61
|
+
/**
|
|
62
|
+
* Returns the PrivateKey associated with the account.
|
|
63
|
+
* @returns {PrivateKey} The private key of the account
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* import { Account } from "@provablehq/sdk/testnet.js";
|
|
67
|
+
*
|
|
68
|
+
* const account = new Account();
|
|
69
|
+
* const privateKey = account.privateKey();
|
|
70
|
+
*/
|
|
53
71
|
privateKey(): PrivateKey;
|
|
72
|
+
/**
|
|
73
|
+
* Returns the ViewKey associated with the account.
|
|
74
|
+
* @returns {ViewKey} The view key of the account
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* import { Account } from "@provablehq/sdk/testnet.js";
|
|
78
|
+
*
|
|
79
|
+
* const account = new Account();
|
|
80
|
+
* const viewKey = account.viewKey();
|
|
81
|
+
*/
|
|
54
82
|
viewKey(): ViewKey;
|
|
83
|
+
/**
|
|
84
|
+
* Returns the ComputeKey associated with the account.
|
|
85
|
+
* @returns {ComputeKey} The compute key of the account
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* import { Account } from "@provablehq/sdk/testnet.js";
|
|
89
|
+
*
|
|
90
|
+
* const account = new Account();
|
|
91
|
+
* const computeKey = account.computeKey();
|
|
92
|
+
*/
|
|
55
93
|
computeKey(): ComputeKey;
|
|
94
|
+
/**
|
|
95
|
+
* Returns the Aleo address associated with the account.
|
|
96
|
+
* @returns {Address} The public address of the account
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* import { Account } from "@provablehq/sdk/testnet.js";
|
|
100
|
+
*
|
|
101
|
+
* const account = new Account();
|
|
102
|
+
* const address = account.address();
|
|
103
|
+
*/
|
|
56
104
|
address(): Address;
|
|
105
|
+
/**
|
|
106
|
+
* Deep clones the Account.
|
|
107
|
+
* @returns {Account} A new Account instance with the same private key
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* import { Account } from "@provablehq/sdk/testnet.js";
|
|
111
|
+
*
|
|
112
|
+
* const account = new Account();
|
|
113
|
+
* const clonedAccount = account.clone();
|
|
114
|
+
*/
|
|
57
115
|
clone(): Account;
|
|
58
|
-
toString(): any;
|
|
59
116
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* @returns {
|
|
117
|
+
* Returns the address of the account in a string representation.
|
|
118
|
+
*
|
|
119
|
+
* @returns {string} The string representation of the account address
|
|
120
|
+
*/
|
|
121
|
+
toString(): string;
|
|
122
|
+
/**
|
|
123
|
+
* Encrypts the account's private key with a password.
|
|
124
|
+
*
|
|
125
|
+
* @param {string} password Password to encrypt the private key.
|
|
126
|
+
* @returns {PrivateKeyCiphertext} The encrypted private key ciphertext
|
|
63
127
|
*
|
|
64
128
|
* @example
|
|
129
|
+
* import { Account } from "@provablehq/sdk/testnet.js";
|
|
130
|
+
*
|
|
65
131
|
* const account = new Account();
|
|
66
132
|
* const ciphertext = account.encryptAccount("password");
|
|
133
|
+
* process.env.ciphertext = ciphertext.toString();
|
|
67
134
|
*/
|
|
68
|
-
encryptAccount(password: string):
|
|
135
|
+
encryptAccount(password: string): PrivateKeyCiphertext;
|
|
69
136
|
/**
|
|
70
|
-
* Decrypts
|
|
71
|
-
*
|
|
72
|
-
* @
|
|
137
|
+
* Decrypts an encrypted record string into a plaintext record object.
|
|
138
|
+
*
|
|
139
|
+
* @param {string} ciphertext A string representing the ciphertext of a record.
|
|
140
|
+
* @returns {RecordPlaintext} The decrypted record plaintext
|
|
73
141
|
*
|
|
74
142
|
* @example
|
|
75
|
-
*
|
|
76
|
-
*
|
|
143
|
+
* // Import the AleoNetworkClient and Account classes
|
|
144
|
+
* import { AleoNetworkClient, Account } from "@provablehq/sdk/testnet.js";
|
|
145
|
+
*
|
|
146
|
+
* // Create a connection to the Aleo network and an account
|
|
147
|
+
* const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
|
|
148
|
+
* const account = Account.fromCiphertext(process.env.ciphertext!, process.env.password!);
|
|
149
|
+
*
|
|
150
|
+
* // Get the record ciphertexts from a transaction.
|
|
151
|
+
* const transaction = await networkClient.getTransactionObject("at1fjy6s9md2v4rgcn3j3q4qndtfaa2zvg58a4uha0rujvrn4cumu9qfazxdd");
|
|
152
|
+
* const records = transaction.records();
|
|
153
|
+
*
|
|
154
|
+
* // Decrypt any records the account owns.
|
|
155
|
+
* const decryptedRecords = [];
|
|
156
|
+
* for (const record of records) {
|
|
157
|
+
* if (account.decryptRecord(record)) {
|
|
158
|
+
* decryptedRecords.push(record);
|
|
159
|
+
* }
|
|
160
|
+
* }
|
|
77
161
|
*/
|
|
78
|
-
decryptRecord(ciphertext: string):
|
|
162
|
+
decryptRecord(ciphertext: string): RecordPlaintext;
|
|
79
163
|
/**
|
|
80
|
-
* Decrypts an array of
|
|
81
|
-
*
|
|
82
|
-
* @
|
|
164
|
+
* Decrypts an array of Record ciphertext strings into an array of record plaintext objects.
|
|
165
|
+
*
|
|
166
|
+
* @param {string[]} ciphertexts An array of strings representing the ciphertexts of records.
|
|
167
|
+
* @returns {RecordPlaintext[]} An array of decrypted record plaintexts
|
|
83
168
|
*
|
|
84
169
|
* @example
|
|
85
|
-
*
|
|
86
|
-
*
|
|
170
|
+
* // Import the AleoNetworkClient and Account classes
|
|
171
|
+
* import { AleoNetworkClient, Account } from "@provablehq/sdk/testnet.js";
|
|
172
|
+
*
|
|
173
|
+
* // Create a connection to the Aleo network and an account
|
|
174
|
+
* const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
|
|
175
|
+
* const account = Account.fromCiphertext(process.env.ciphertext!, process.env.password!);
|
|
176
|
+
*
|
|
177
|
+
* // Get the record ciphertexts from a transaction.
|
|
178
|
+
* const transaction = await networkClient.getTransactionObject("at1fjy6s9md2v4rgcn3j3q4qndtfaa2zvg58a4uha0rujvrn4cumu9qfazxdd");
|
|
179
|
+
* const records = transaction.records();
|
|
180
|
+
*
|
|
181
|
+
* // Decrypt any records the account owns. If the account owns no records, the array will be empty.
|
|
182
|
+
* const decryptedRecords = account.decryptRecords(records);
|
|
87
183
|
*/
|
|
88
|
-
decryptRecords(ciphertexts: string[]):
|
|
184
|
+
decryptRecords(ciphertexts: string[]): RecordPlaintext[];
|
|
89
185
|
/**
|
|
90
|
-
* Determines whether the account owns a ciphertext record
|
|
91
|
-
* @param {
|
|
92
|
-
* @returns {boolean}
|
|
186
|
+
* Determines whether the account owns a ciphertext record.
|
|
187
|
+
* @param {RecordCiphertext | string} ciphertext The record ciphertext to check ownership of
|
|
188
|
+
* @returns {boolean} True if the account owns the record, false otherwise
|
|
93
189
|
*
|
|
94
190
|
* @example
|
|
191
|
+
* // Import the AleoNetworkClient and Account classes
|
|
192
|
+
* import { AleoNetworkClient, Account } from "@provablehq/sdk/testnet.js";
|
|
193
|
+
*
|
|
95
194
|
* // Create a connection to the Aleo network and an account
|
|
96
|
-
* const
|
|
97
|
-
* const account = Account.fromCiphertext(process.env.ciphertext
|
|
195
|
+
* const networkClient = new AleoNetworkClient("https://api.explorer.provable.com/v1");
|
|
196
|
+
* const account = Account.fromCiphertext(process.env.ciphertext!, process.env.password!);
|
|
98
197
|
*
|
|
99
|
-
* // Get
|
|
100
|
-
* const
|
|
101
|
-
* const
|
|
198
|
+
* // Get the record ciphertexts from a transaction and check ownership of them.
|
|
199
|
+
* const transaction = await networkClient.getTransactionObject("at1fjy6s9md2v4rgcn3j3q4qndtfaa2zvg58a4uha0rujvrn4cumu9qfazxdd");
|
|
200
|
+
* const records = transaction.records();
|
|
102
201
|
*
|
|
103
|
-
* // Check if the account owns the record
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
202
|
+
* // Check if the account owns any of the record ciphertexts present in the transaction.
|
|
203
|
+
* const ownedRecords = [];
|
|
204
|
+
* for (const record of records) {
|
|
205
|
+
* if (account.ownsRecordCiphertext(record)) {
|
|
206
|
+
* ownedRecords.push(record);
|
|
207
|
+
* }
|
|
109
208
|
* }
|
|
110
209
|
*/
|
|
111
|
-
ownsRecordCiphertext(ciphertext: RecordCiphertext | string):
|
|
210
|
+
ownsRecordCiphertext(ciphertext: RecordCiphertext | string): boolean;
|
|
112
211
|
/**
|
|
113
212
|
* Signs a message with the account's private key.
|
|
114
213
|
* Returns a Signature.
|
|
115
214
|
*
|
|
116
|
-
* @param {Uint8Array} message
|
|
117
|
-
* @returns {Signature}
|
|
215
|
+
* @param {Uint8Array} message Message to be signed.
|
|
216
|
+
* @returns {Signature} Signature over the message in bytes.
|
|
118
217
|
*
|
|
119
218
|
* @example
|
|
219
|
+
* // Import the Account class
|
|
220
|
+
* import { Account } from "@provablehq/sdk/testnet.js";
|
|
221
|
+
*
|
|
222
|
+
* // Create a connection to the Aleo network and an account
|
|
223
|
+
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
224
|
+
*
|
|
225
|
+
* // Create an account and a message to sign.
|
|
120
226
|
* const account = new Account();
|
|
121
227
|
* const message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
|
|
122
|
-
* account.sign(message);
|
|
228
|
+
* const signature = account.sign(message);
|
|
229
|
+
*
|
|
230
|
+
* // Verify the signature.
|
|
231
|
+
* assert(account.verify(message, signature));
|
|
123
232
|
*/
|
|
124
|
-
sign(message: Uint8Array):
|
|
233
|
+
sign(message: Uint8Array): Signature;
|
|
125
234
|
/**
|
|
126
235
|
* Verifies the Signature on a message.
|
|
127
236
|
*
|
|
128
|
-
* @param {Uint8Array} message
|
|
129
|
-
* @param {Signature} signature
|
|
130
|
-
* @returns {boolean}
|
|
237
|
+
* @param {Uint8Array} message Message in bytes to be signed.
|
|
238
|
+
* @param {Signature} signature Signature to be verified.
|
|
239
|
+
* @returns {boolean} True if the signature is valid, false otherwise.
|
|
131
240
|
*
|
|
132
241
|
* @example
|
|
133
|
-
*
|
|
242
|
+
* // Import the Account class
|
|
243
|
+
* import { Account } from "@provablehq/sdk/testnet.js";
|
|
244
|
+
*
|
|
245
|
+
* // Create a connection to the Aleo network and an account
|
|
246
|
+
* const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
|
|
247
|
+
*
|
|
248
|
+
* // Sign a message.
|
|
134
249
|
* const message = Uint8Array.from([104, 101, 108, 108, 111 119, 111, 114, 108, 100])
|
|
135
250
|
* const signature = account.sign(message);
|
|
136
|
-
*
|
|
251
|
+
*
|
|
252
|
+
* // Verify the signature.
|
|
253
|
+
* assert(account.verify(message, signature));
|
|
137
254
|
*/
|
|
138
|
-
verify(message: Uint8Array, signature: Signature):
|
|
255
|
+
verify(message: Uint8Array, signature: Signature): boolean;
|
|
139
256
|
}
|
|
140
257
|
export {};
|
|
@@ -9,6 +9,7 @@ import { ExecutionJSON, FeeExecutionJSON } from "./models/execution/executionJSO
|
|
|
9
9
|
import { ExecutionObject, FeeExecutionObject } from "./models/execution/executionObject";
|
|
10
10
|
import { FinalizeJSON } from "./models/finalizeJSON";
|
|
11
11
|
import { FunctionObject } from "./models/functionObject";
|
|
12
|
+
import { ImportedVerifyingKeys, ImportedPrograms } from "./models/imports";
|
|
12
13
|
import { InputJSON } from "./models/input/inputJSON";
|
|
13
14
|
import { InputObject } from "./models/input/inputObject";
|
|
14
15
|
import { OutputJSON } from "./models/output/outputJSON";
|
|
@@ -34,4 +35,4 @@ export { logAndThrow } from "./utils";
|
|
|
34
35
|
export { Address, BHP256, BHP512, BHP768, BHP1024, Ciphertext, ComputeKey, Execution as FunctionExecution, ExecutionResponse, Field, Group, OfflineQuery, Pedersen64, Pedersen128, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager as ProgramManagerBase, ProvingKey, RecordCiphertext, RecordPlaintext, Signature, Scalar, Transaction, Transition, VerifyingKey, ViewKey, initThreadPool, verifyFunctionExecution, } from "./wasm";
|
|
35
36
|
export { initializeWasm };
|
|
36
37
|
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, VALID_TRANSFER_TYPES, } from "./constants";
|
|
37
|
-
export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, AleoNetworkClient, BlockJSON, BlockHeightSearch, CachedKeyPair, ConfirmedTransactionJSON, DeploymentJSON, DeploymentObject, ExecutionJSON, ExecutionObject, FeeExecutionJSON, FeeExecutionObject, FinalizeJSON, FunctionObject, FunctionKeyPair, FunctionKeyProvider, Header, InputJSON, InputObject, KeySearchParams, Metadata, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, OutputJSON, OutputObject, OwnerJSON, PartialSolutionJSON, PlaintextArray, PlaintextLiteral, PlaintextObject, PlaintextStruct, ProgramImports, RatificationJSON, RecordProvider, RecordSearchParams, SolutionJSON, SolutionsJSON, TransactionJSON, TransactionObject, TransitionJSON, TransitionObject, VerifyingKeys, };
|
|
38
|
+
export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, AleoNetworkClient, BlockJSON, BlockHeightSearch, CachedKeyPair, ConfirmedTransactionJSON, DeploymentJSON, DeploymentObject, ExecutionJSON, ExecutionObject, FeeExecutionJSON, FeeExecutionObject, FinalizeJSON, FunctionObject, FunctionKeyPair, FunctionKeyProvider, Header, ImportedPrograms, ImportedVerifyingKeys, InputJSON, InputObject, KeySearchParams, Metadata, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, OutputJSON, OutputObject, OwnerJSON, PartialSolutionJSON, PlaintextArray, PlaintextLiteral, PlaintextObject, PlaintextStruct, ProgramImports, RatificationJSON, RecordProvider, RecordSearchParams, SolutionJSON, SolutionsJSON, TransactionJSON, TransactionObject, TransitionJSON, TransitionObject, VerifyingKeys, };
|