@provablehq/sdk 0.10.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mainnet/browser.d.ts +1 -1
- package/dist/mainnet/browser.js +65 -13
- package/dist/mainnet/browser.js.map +1 -1
- package/dist/mainnet/node.js +1 -1
- package/dist/mainnet/program-manager.d.ts +20 -2
- package/dist/mainnet/wasm.d.ts +1 -1
- package/dist/testnet/browser.d.ts +1 -1
- package/dist/testnet/browser.js +65 -13
- package/dist/testnet/browser.js.map +1 -1
- package/dist/testnet/node.js +1 -1
- package/dist/testnet/program-manager.d.ts +20 -2
- package/dist/testnet/wasm.d.ts +1 -1
- package/package.json +2 -2
|
@@ -62,7 +62,7 @@ import { SealanceMerkleTree } from "./integrations/sealance/merkle-tree.js";
|
|
|
62
62
|
declare function initializeWasm(): Promise<void>;
|
|
63
63
|
export { ProgramManager, ProvingRequestOptions, ExecuteOptions, FeeAuthorizationOptions, AuthorizationOptions, VerificationOptions, BatchVerificationOptions, inputsToFields, verifyProof, verifyBatchProof } from "./program-manager.js";
|
|
64
64
|
export { logAndThrow } from "./utils.js";
|
|
65
|
-
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, Proof, ProvingKey, ProvingRequest, RecordCiphertext, RecordPlaintext, Signature, Scalar, stringToField, Transaction, Transition, U8, U16, U32, U64, U128, Value, VerifyingKey, ViewKey, initThreadPool, getOrInitConsensusVersionTestHeights, snarkVerify, snarkVerifyBatch, verifyFunctionExecution, } from "./wasm.js";
|
|
65
|
+
export { Address, Authorization, Boolean, BHP256, BHP512, BHP768, BHP1024, Ciphertext, ComputeKey, DynamicRecord, 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, Proof, ProvingKey, ProvingRequest, RecordCiphertext, RecordPlaintext, Signature, Scalar, stringToField, Transaction, Transition, U8, U16, U32, U64, U128, Value, VerifyingKey, ViewKey, initThreadPool, getOrInitConsensusVersionTestHeights, snarkVerify, snarkVerifyBatch, verifyFunctionExecution, } from "./wasm.js";
|
|
66
66
|
export { initializeWasm };
|
|
67
67
|
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";
|
|
68
68
|
export { Account, AleoKeyProvider, AleoKeyProviderParams, AleoKeyProviderInitParams, AleoNetworkClient, BlockJSON, BlockHeightSearch, BroadcastResponse, BroadcastResult, CachedKeyPair, ConfirmedTransactionJSON, CryptoBoxPubKey, DecryptionNotEnabledError, DeploymentJSON, DeploymentObject, EncryptedProvingRequest, EncryptedRecord, EncryptedRegistrationRequest, EncryptedRecordsResult, EncryptedRecordsSuccess, ExecutionJSON, ExecutionObject, FeeExecutionJSON, FeeExecutionObject, FinalizeJSON, FunctionInput, FunctionObject, FunctionKeyPair, FunctionKeyProvider, Header, isProvingResponse, isProveApiErrorBody, ImportedPrograms, ImportedVerifyingKeys, InputJSON, InputObject, InvalidLocatorError, InvalidLocatorReason, BaseFunctionKeyLocator, KeyFingerprint, KeyLocator, KeyMetadata, KeySearchParams, KeyStore, KeyType, KeyVerificationError, ProvingKeyLocator, provingKeyLocator, TranslationKeyLocator, translationKeyLocator, VerifyingKeyLocator, verifyingKeyLocator, KeyVerifier, MemKeyVerifier, Metadata, NetworkRecordProvider, OfflineKeyProvider, OfflineSearchParams, OutputJSON, OutputObject, OwnedFilter, OwnedRecord, OwnedRecordsResult, OwnedRecordsResponseFilter, OwnedRecordsSuccess, OwnerJSON, PartialSolutionJSON, PlaintextArray, PlaintextLiteral, PlaintextObject, PlaintextStruct, ProgramImports, ProveApiErrorBody, ProvingFailure, ProvingRequestError, ProvingRequestJSON, ProvingResult, ProvingSuccess, ProvingResponse, RatificationJSON, RecordsFilter, RecordsResponseFilter, RecordProvider, RecordScanner, RecordScannerErrorBody, RecordScannerFailure, RecordScannerJWTData, RecordScannerOptions, RecordNotFoundError, RecordScannerRequestError, ViewKeyNotStoredError, RecordSearchParams, RegisterResult, RegisterSuccess, RegistrationRequest, RegistrationResponse, RevokeResult, RevokeSuccess, RevokeResponse, SealanceMerkleTree, SerialNumbersResult, SerialNumbersSuccess, sha256Hex, SolutionJSON, SolutionsJSON, StatusResponse, StatusResult, StatusSuccess, TagsResult, TagsSuccess, TransactionJSON, TransactionObject, TransitionJSON, TransitionObject, UUIDError, VerifyingKeys, };
|
package/dist/mainnet/browser.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import 'core-js/proposals/json-parse-with-source.js';
|
|
2
|
-
import { ViewKey, ComputeKey, Address, PrivateKeyCiphertext, PrivateKey, RecordCiphertext, EncryptionToolkit, Group, Metadata, VerifyingKey, Program, Plaintext, Transaction, ProvingRequest, ProvingKey, RecordPlaintext, Field, Poseidon4, ProgramManager as ProgramManager$1, ExecutionRequest, verifyFunctionExecution, Value, Proof, Signature } from '@provablehq/wasm/mainnet.js';
|
|
3
|
-
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, Proof, ProvingKey, ProvingRequest, RecordCiphertext, RecordPlaintext, Scalar, Signature, Transaction, Transition, U128, U16, U32, U64, U8, Value, VerifyingKey, ViewKey, getOrInitConsensusVersionTestHeights, initThreadPool, snarkVerify, snarkVerifyBatch, stringToField, verifyFunctionExecution } from '@provablehq/wasm/mainnet.js';
|
|
2
|
+
import { ViewKey, ComputeKey, Address, PrivateKeyCiphertext, PrivateKey, RecordCiphertext, EncryptionToolkit, Group, Metadata, VerifyingKey, Program, Plaintext, Transaction, ProvingRequest, ProvingKey, RecordPlaintext, Field, Poseidon4, ProgramManager as ProgramManager$1, ExecutionRequest, stringToField, verifyFunctionExecution, Value, Proof, Signature } from '@provablehq/wasm/mainnet.js';
|
|
3
|
+
export { Address, Authorization, BHP1024, BHP256, BHP512, BHP768, Boolean, Ciphertext, ComputeKey, DynamicRecord, EncryptionToolkit, ExecutionRequest, ExecutionResponse, Field, Execution as FunctionExecution, GraphKey, Group, I128, I16, I32, I64, I8, OfflineQuery, Pedersen128, Pedersen64, Plaintext, Poseidon2, Poseidon4, Poseidon8, PrivateKey, PrivateKeyCiphertext, Program, ProgramManager as ProgramManagerBase, Proof, ProvingKey, ProvingRequest, RecordCiphertext, RecordPlaintext, Scalar, Signature, Transaction, Transition, U128, U16, U32, U64, U8, Value, VerifyingKey, ViewKey, getOrInitConsensusVersionTestHeights, initThreadPool, snarkVerify, snarkVerifyBatch, stringToField, verifyFunctionExecution } from '@provablehq/wasm/mainnet.js';
|
|
4
4
|
import sodium from 'libsodium-wrappers';
|
|
5
5
|
import { bech32m } from '@scure/base';
|
|
6
6
|
|
|
@@ -849,7 +849,7 @@ class AleoNetworkClient {
|
|
|
849
849
|
else {
|
|
850
850
|
this.headers = {
|
|
851
851
|
// This is replaced by the actual version by a Rollup plugin
|
|
852
|
-
"X-Aleo-SDK-Version": "0.10.
|
|
852
|
+
"X-Aleo-SDK-Version": "0.10.1",
|
|
853
853
|
"X-Aleo-environment": environment(),
|
|
854
854
|
};
|
|
855
855
|
}
|
|
@@ -865,7 +865,7 @@ class AleoNetworkClient {
|
|
|
865
865
|
else {
|
|
866
866
|
this.headers = {
|
|
867
867
|
// This is replaced by the actual version by a Rollup plugin
|
|
868
|
-
"X-Aleo-SDK-Version": "0.10.
|
|
868
|
+
"X-Aleo-SDK-Version": "0.10.1",
|
|
869
869
|
"X-Aleo-environment": environment(),
|
|
870
870
|
};
|
|
871
871
|
}
|
|
@@ -5718,8 +5718,10 @@ class ProgramManager {
|
|
|
5718
5718
|
logAndThrow(`Inclusion key bytes not loaded, please ensure the program manager is initialized with a KeyProvider that includes the inclusion key.`);
|
|
5719
5719
|
}
|
|
5720
5720
|
}
|
|
5721
|
+
// Auto-convert bare string inputs to field elements where the function expects field type.
|
|
5722
|
+
const preparedInputs = this.prepareInputs(program, functionName, inputs);
|
|
5721
5723
|
// Build an execution transaction
|
|
5722
|
-
return await ProgramManager$1.buildExecutionTransaction(executionPrivateKey, program, functionName,
|
|
5724
|
+
return await ProgramManager$1.buildExecutionTransaction(executionPrivateKey, program, functionName, preparedInputs, priorityFee, feeRecord, this.host, imports, provingKey, verifyingKey, feeProvingKey, feeVerifyingKey, offlineQuery, edition);
|
|
5723
5725
|
}
|
|
5724
5726
|
/**
|
|
5725
5727
|
* Builds an execution transaction for submission to the Aleo network from an Authorization and Fee Authorization.
|
|
@@ -5942,8 +5944,10 @@ class ProgramManager {
|
|
|
5942
5944
|
logAndThrow(`Error finding program imports. Network response: '${e.message}'. Please ensure you're connected to a valid Aleo network and the program is deployed to the network.`);
|
|
5943
5945
|
}
|
|
5944
5946
|
}
|
|
5947
|
+
// Auto-convert bare string inputs to field elements where the function expects field type.
|
|
5948
|
+
const preparedInputs = this.prepareInputs(program, functionName, inputs);
|
|
5945
5949
|
// Build and return an `Authorization` for the desired function.
|
|
5946
|
-
return await ProgramManager$1.authorize(executionPrivateKey, program, functionName,
|
|
5950
|
+
return await ProgramManager$1.authorize(executionPrivateKey, program, functionName, preparedInputs, imports, edition);
|
|
5947
5951
|
}
|
|
5948
5952
|
/**
|
|
5949
5953
|
* Builds a SnarkVM `Authorization` for a specific function without building a circuit first. This should be used when fast authorization generation is needed and the invoker is confident inputs are coorect.
|
|
@@ -6025,8 +6029,10 @@ class ProgramManager {
|
|
|
6025
6029
|
edition = 0;
|
|
6026
6030
|
}
|
|
6027
6031
|
}
|
|
6032
|
+
// Auto-convert bare string inputs to field elements where the function expects field type.
|
|
6033
|
+
const preparedInputs = this.prepareInputs(program, functionName, inputs);
|
|
6028
6034
|
// Build and return an `Authorization` for the desired function.
|
|
6029
|
-
return await ProgramManager$1.buildAuthorizationUnchecked(executionPrivateKey, program, functionName,
|
|
6035
|
+
return await ProgramManager$1.buildAuthorizationUnchecked(executionPrivateKey, program, functionName, preparedInputs, imports, edition);
|
|
6030
6036
|
}
|
|
6031
6037
|
/**
|
|
6032
6038
|
* Builds a `ProvingRequest` for submission to a prover for execution. If building a proving request with an ExecutionRequest, a private key must be explicitly provided.
|
|
@@ -6147,8 +6153,10 @@ class ProgramManager {
|
|
|
6147
6153
|
if (!inputs) {
|
|
6148
6154
|
throw new Error("No inputs provided to build a proving request");
|
|
6149
6155
|
}
|
|
6156
|
+
// Auto-convert bare string inputs to field elements where the function expects field type.
|
|
6157
|
+
const preparedInputs = this.prepareInputs(program, functionName, inputs);
|
|
6150
6158
|
// Build and return the `ProvingRequest`.
|
|
6151
|
-
return await ProgramManager$1.buildProvingRequest(executionPrivateKey, program, functionName,
|
|
6159
|
+
return await ProgramManager$1.buildProvingRequest(executionPrivateKey, program, functionName, preparedInputs, baseFee, priorityFee, feeRecord, imports, broadcast, unchecked, edition, useFeeMaster);
|
|
6152
6160
|
}
|
|
6153
6161
|
}
|
|
6154
6162
|
/**
|
|
@@ -6250,6 +6258,44 @@ class ProgramManager {
|
|
|
6250
6258
|
}
|
|
6251
6259
|
return await this.networkClient.submitTransaction(tx);
|
|
6252
6260
|
}
|
|
6261
|
+
/**
|
|
6262
|
+
* Prepares user-provided inputs for a function call by auto-converting bare
|
|
6263
|
+
* string identifiers to field elements where the function signature expects
|
|
6264
|
+
* a `field` type. This lets callers of dynamic-dispatch programs pass
|
|
6265
|
+
* human-readable strings (e.g. `"my_program"`) instead of requiring
|
|
6266
|
+
* `stringToField("my_program").toString()`.
|
|
6267
|
+
*
|
|
6268
|
+
* Inputs that already look like a numeric field literal (matching
|
|
6269
|
+
* `/^\d+field$/` after trimming whitespace) are left untouched. Non-field
|
|
6270
|
+
* inputs are returned as-is. If introspection fails for any reason the
|
|
6271
|
+
* original inputs are returned unchanged.
|
|
6272
|
+
*
|
|
6273
|
+
* @param {string | Program} programSource - The program source code or Program object
|
|
6274
|
+
* @param {string} functionName - The function to inspect
|
|
6275
|
+
* @param {string[]} inputs - The raw user-provided inputs
|
|
6276
|
+
* @returns {string[]} The (possibly converted) inputs
|
|
6277
|
+
*/
|
|
6278
|
+
prepareInputs(programSource, functionName, inputs) {
|
|
6279
|
+
try {
|
|
6280
|
+
const source = typeof programSource === "string" ? programSource : programSource.toString();
|
|
6281
|
+
const programObj = Program.fromString(source);
|
|
6282
|
+
const functionInputs = programObj.getFunctionInputs(functionName);
|
|
6283
|
+
if (functionInputs.length !== inputs.length) {
|
|
6284
|
+
return inputs;
|
|
6285
|
+
}
|
|
6286
|
+
return inputs.map((input, i) => {
|
|
6287
|
+
const spec = functionInputs[i];
|
|
6288
|
+
const isFieldLiteral = /^\d+field$/.test(input.trim());
|
|
6289
|
+
if (spec?.type === "field" && !isFieldLiteral) {
|
|
6290
|
+
return stringToField(input).toString();
|
|
6291
|
+
}
|
|
6292
|
+
return input;
|
|
6293
|
+
});
|
|
6294
|
+
}
|
|
6295
|
+
catch {
|
|
6296
|
+
return inputs;
|
|
6297
|
+
}
|
|
6298
|
+
}
|
|
6253
6299
|
/**
|
|
6254
6300
|
* Run an Aleo program in offline mode
|
|
6255
6301
|
*
|
|
@@ -6301,11 +6347,13 @@ class ProgramManager {
|
|
|
6301
6347
|
console.log(`Function keys not found. Key finder response: '${e}'. The function keys will be synthesized`);
|
|
6302
6348
|
}
|
|
6303
6349
|
}
|
|
6350
|
+
// Auto-convert bare string inputs to field elements where the function expects field type.
|
|
6351
|
+
const preparedInputs = this.prepareInputs(program, function_name, inputs);
|
|
6304
6352
|
// Run the program offline and return the result
|
|
6305
6353
|
console.log("Running program offline");
|
|
6306
6354
|
console.log("Proving key: ", provingKey);
|
|
6307
6355
|
console.log("Verifying key: ", verifyingKey);
|
|
6308
|
-
return ProgramManager$1.executeFunctionOffline(executionPrivateKey, program, function_name,
|
|
6356
|
+
return ProgramManager$1.executeFunctionOffline(executionPrivateKey, program, function_name, preparedInputs, proveExecution, false, imports, provingKey, verifyingKey, this.host, offlineQuery, edition);
|
|
6309
6357
|
}
|
|
6310
6358
|
/**
|
|
6311
6359
|
* Join two credits records into a single credits record
|
|
@@ -6520,10 +6568,12 @@ class ProgramManager {
|
|
|
6520
6568
|
executionPrivateKey = new PrivateKey();
|
|
6521
6569
|
}
|
|
6522
6570
|
}
|
|
6571
|
+
// Auto-convert bare string inputs to field elements where the function expects field type.
|
|
6572
|
+
const preparedInputs = this.prepareInputs(program, function_id, inputs);
|
|
6523
6573
|
// Attempt to run an offline execution of the program and extract the proving and verifying keys
|
|
6524
6574
|
try {
|
|
6525
6575
|
imports = await this.networkClient.getProgramImports(program);
|
|
6526
|
-
const keyPair = await ProgramManager$1.synthesizeKeyPair(executionPrivateKey, program, function_id,
|
|
6576
|
+
const keyPair = await ProgramManager$1.synthesizeKeyPair(executionPrivateKey, program, function_id, preparedInputs, imports);
|
|
6527
6577
|
return [
|
|
6528
6578
|
keyPair.provingKey(),
|
|
6529
6579
|
keyPair.verifyingKey(),
|
|
@@ -7491,7 +7541,7 @@ class ProgramManager {
|
|
|
7491
7541
|
* import { AleoKeyProvider, getOrInitConsensusVersionTestHeights, ProgramManager, NetworkRecordProvider } from "@provablehq/sdk/mainnet.js";
|
|
7492
7542
|
*
|
|
7493
7543
|
* // Initialize the development consensus heights in order to work with devnode.
|
|
7494
|
-
* getOrInitConsensusVersionTestHeights("0,1,2,3,4,5,6,7,8,9,10,11,12");
|
|
7544
|
+
* getOrInitConsensusVersionTestHeights("0,1,2,3,4,5,6,7,8,9,10,11,12,13");
|
|
7495
7545
|
*
|
|
7496
7546
|
* // Create a new NetworkClient and RecordProvider.
|
|
7497
7547
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|
|
@@ -7607,8 +7657,10 @@ class ProgramManager {
|
|
|
7607
7657
|
logAndThrow(`Error finding program imports. Network response: '${e.message}'. Please ensure you're connected to a valid Aleo network and the program is deployed to the network.`);
|
|
7608
7658
|
}
|
|
7609
7659
|
}
|
|
7660
|
+
// Auto-convert bare string inputs to field elements where the function expects field type.
|
|
7661
|
+
const preparedInputs = this.prepareInputs(program, functionName, inputs);
|
|
7610
7662
|
// Build a transaction without a proof
|
|
7611
|
-
return await ProgramManager$1.buildDevnodeExecutionTransaction(executionPrivateKey, program, functionName,
|
|
7663
|
+
return await ProgramManager$1.buildDevnodeExecutionTransaction(executionPrivateKey, program, functionName, preparedInputs, priorityFee, feeRecord, this.host, imports, edition);
|
|
7612
7664
|
}
|
|
7613
7665
|
/**
|
|
7614
7666
|
* Builds a deployment transaction with placeholder certificates and verifying keys for each function in the program.
|
|
@@ -7623,7 +7675,7 @@ class ProgramManager {
|
|
|
7623
7675
|
* import { ProgramManager, NetworkRecordProvider, getOrInitConsensusVersionTestHeights } from "@provablehq/sdk/mainnet.js";
|
|
7624
7676
|
*
|
|
7625
7677
|
* // Initialize the development consensus heights in order to work with a local devnode.
|
|
7626
|
-
* getOrInitConsensusVersionTestHeights("0,1,2,3,4,5,6,7,8,9,10,11,12");
|
|
7678
|
+
* getOrInitConsensusVersionTestHeights("0,1,2,3,4,5,6,7,8,9,10,11,12,13");
|
|
7627
7679
|
*
|
|
7628
7680
|
* // Create a new NetworkClient, and RecordProvider
|
|
7629
7681
|
* const recordProvider = new NetworkRecordProvider(account, networkClient);
|