@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.
@@ -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
- * 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.
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: 'myExistingPrivateKey'})
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 {PrivateKey}
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
- * const ciphertext = PrivateKey.newEncrypted("password");
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
- * Encrypt the account's private key with a password
61
- * @param {string} ciphertext
62
- * @returns {PrivateKeyCiphertext}
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): any;
135
+ encryptAccount(password: string): PrivateKeyCiphertext;
69
136
  /**
70
- * Decrypts a Record in ciphertext form into plaintext
71
- * @param {string} ciphertext
72
- * @returns {Record}
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
- * const account = new Account();
76
- * const record = account.decryptRecord("record1ciphertext");
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): any;
162
+ decryptRecord(ciphertext: string): RecordPlaintext;
79
163
  /**
80
- * Decrypts an array of Records in ciphertext form into plaintext
81
- * @param {string[]} ciphertexts
82
- * @returns {Record[]}
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
- * const account = new Account();
86
- * const record = account.decryptRecords(["record1ciphertext", "record2ciphertext"]);
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[]): any[];
184
+ decryptRecords(ciphertexts: string[]): RecordPlaintext[];
89
185
  /**
90
- * Determines whether the account owns a ciphertext record
91
- * @param {RecordCipherText | string} ciphertext
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 connection = new AleoNetworkClient("https://api.explorer.provable.com/v1");
97
- * const account = Account.fromCiphertext(process.env.ciphertext, process.env.password);
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 a record from the network
100
- * const record = connection.getBlock(1234);
101
- * const recordCipherText = record.transactions[0].execution.transitions[0].id;
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
- * if account.ownsRecord(recordCipherText) {
105
- * // Then one can do something like:
106
- * // Decrypt the record and check if it's spent
107
- * // Store the record in a local database
108
- * // Etc.
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): any;
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): any;
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
- * const account = new Account();
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
- * account.verify(message, signature);
251
+ *
252
+ * // Verify the signature.
253
+ * assert(account.verify(message, signature));
137
254
  */
138
- verify(message: Uint8Array, signature: Signature): any;
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, };