@taquito/sapling 24.3.0-rc.1 → 24.3.0-rc.3
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/SAPLING_PARAMS_PROVENANCE.md +16 -10
- package/dist/lib/sapling-module-wrapper.js +3 -12
- package/dist/lib/sapling-params-loader.js +180 -0
- package/dist/lib/sapling-params-manifest.json +15 -0
- package/dist/lib/taquito-sapling.js +5 -1
- package/dist/lib/version.js +2 -2
- package/dist/taquito-sapling.es6.js +189 -21
- package/dist/taquito-sapling.es6.js.map +1 -1
- package/dist/taquito-sapling.umd.js +194 -21
- package/dist/taquito-sapling.umd.js.map +1 -1
- package/dist/types/sapling-params-loader.d.ts +9 -0
- package/dist/types/taquito-sapling.d.ts +2 -0
- package/dist/types/types.d.ts +28 -0
- package/package.json +9 -10
- package/src/sapling-params-manifest.json +15 -0
- package/dist/lib/sapling-output-params.js +0 -12
- package/dist/types/sapling-output-params.d.ts +0 -6
- package/saplingOutputParams.d.ts +0 -5
- package/saplingOutputParams.js +0 -16
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('bignumber.js'), require('@taquito/taquito'), require('@taquito/utils'), require('@taquito/core'), require('@taquito/sapling-wasm'), require('blakejs'), require('@stablelib/nacl'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'bignumber.js', '@taquito/taquito', '@taquito/utils', '@taquito/core', '@taquito/sapling-wasm', 'blakejs', '@stablelib/nacl', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoSapling = {}, global.BigNumber, global.taquito, global.utils, global.core, global.sapling, global.blake, global.nacl,
|
|
5
|
-
})(this, (function (exports, BigNumberJs, taquito, utils, core, saplingWasm, blake, nacl,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('bignumber.js'), require('@taquito/taquito'), require('@taquito/utils'), require('@taquito/core'), require('@taquito/sapling-wasm'), require('blakejs'), require('@stablelib/nacl'), require('typedarray-to-buffer')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'bignumber.js', '@taquito/taquito', '@taquito/utils', '@taquito/core', '@taquito/sapling-wasm', 'blakejs', '@stablelib/nacl', 'typedarray-to-buffer'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.taquitoSapling = {}, global.BigNumber, global.taquito, global.utils, global.core, global.sapling, global.blake, global.nacl, global.toBuffer));
|
|
5
|
+
})(this, (function (exports, BigNumberJs, taquito, utils, core, saplingWasm, blake, nacl, toBuffer) { 'use strict';
|
|
6
6
|
|
|
7
7
|
/******************************************************************************
|
|
8
8
|
Copyright (c) Microsoft Corporation.
|
|
@@ -2964,17 +2964,193 @@
|
|
|
2964
2964
|
}
|
|
2965
2965
|
}
|
|
2966
2966
|
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2967
|
+
var spendParams = {
|
|
2968
|
+
sha256: "8e48ffd23abb3a5fd9c5589204f32d9c31285a04b78096ba40a79b75677efc13",
|
|
2969
|
+
taquitoUrl: "https://sapling.taquito.io/params/groth16-mainnet-1/spend.params",
|
|
2970
|
+
zcashUrl: "https://download.z.cash/downloads/sapling-spend.params"
|
|
2971
|
+
};
|
|
2972
|
+
var outputParams = {
|
|
2973
|
+
sha256: "2f0ebbcbb9bb0bcffe95a397e7eba89c29eb4dde6191c339db88570e3f3fb0e4",
|
|
2974
|
+
taquitoUrl: "https://sapling.taquito.io/params/groth16-mainnet-1/output.params",
|
|
2975
|
+
zcashUrl: "https://download.z.cash/downloads/sapling-output.params"
|
|
2976
|
+
};
|
|
2977
|
+
var saplingParamsManifest = {
|
|
2978
|
+
spendParams: spendParams,
|
|
2979
|
+
outputParams: outputParams
|
|
2974
2980
|
};
|
|
2975
|
-
var saplingOutputParams = loadSaplingOutputParams();
|
|
2976
2981
|
|
|
2977
|
-
|
|
2982
|
+
const DEFAULT_SAPLING_PARAMS_MANIFEST = saplingParamsManifest;
|
|
2983
|
+
class SaplingParamsError extends Error {
|
|
2984
|
+
constructor(code, message, source, cause) {
|
|
2985
|
+
super(message);
|
|
2986
|
+
this.code = code;
|
|
2987
|
+
this.source = source;
|
|
2988
|
+
this.name = 'SaplingParamsError';
|
|
2989
|
+
this.cause = cause;
|
|
2990
|
+
}
|
|
2991
|
+
}
|
|
2992
|
+
let configuredSaplingParamsSource;
|
|
2993
|
+
let frozenSaplingParamsSource;
|
|
2994
|
+
let loadedSaplingParams;
|
|
2995
|
+
let saplingParamsLoadPromise;
|
|
2996
|
+
let saplingParamsInitPromise;
|
|
2997
|
+
async function initSapling(options = {}) {
|
|
2998
|
+
const nextSource = resolveSaplingParamsSource(options.params);
|
|
2999
|
+
if (frozenSaplingParamsSource || saplingParamsLoadPromise || saplingParamsInitPromise) {
|
|
3000
|
+
return;
|
|
3001
|
+
}
|
|
3002
|
+
configuredSaplingParamsSource = nextSource;
|
|
3003
|
+
}
|
|
3004
|
+
async function preloadSaplingParams() {
|
|
3005
|
+
if (!saplingParamsInitPromise) {
|
|
3006
|
+
saplingParamsInitPromise = initializeSaplingParams().catch((error) => {
|
|
3007
|
+
saplingParamsInitPromise = undefined;
|
|
3008
|
+
throw error;
|
|
3009
|
+
});
|
|
3010
|
+
}
|
|
3011
|
+
return saplingParamsInitPromise;
|
|
3012
|
+
}
|
|
3013
|
+
async function initializeSaplingParams() {
|
|
3014
|
+
const { spend, output } = await loadSaplingParams();
|
|
3015
|
+
await saplingWasm.initParameters(spend, output);
|
|
3016
|
+
}
|
|
3017
|
+
async function loadSaplingParams() {
|
|
3018
|
+
if (loadedSaplingParams) {
|
|
3019
|
+
return loadedSaplingParams;
|
|
3020
|
+
}
|
|
3021
|
+
if (!saplingParamsLoadPromise) {
|
|
3022
|
+
const source = frozenSaplingParamsSource ?? configuredSaplingParamsSource ?? resolveSaplingParamsSource();
|
|
3023
|
+
saplingParamsLoadPromise = loadSaplingParamsFromSource(source)
|
|
3024
|
+
.then((params) => {
|
|
3025
|
+
frozenSaplingParamsSource = source;
|
|
3026
|
+
loadedSaplingParams = params;
|
|
3027
|
+
return params;
|
|
3028
|
+
})
|
|
3029
|
+
.catch((error) => {
|
|
3030
|
+
saplingParamsLoadPromise = undefined;
|
|
3031
|
+
throw error;
|
|
3032
|
+
});
|
|
3033
|
+
}
|
|
3034
|
+
return saplingParamsLoadPromise;
|
|
3035
|
+
}
|
|
3036
|
+
async function loadSaplingParamsFromSource(source) {
|
|
3037
|
+
if (source.kind === 'local') {
|
|
3038
|
+
const [spend, output] = await Promise.all([
|
|
3039
|
+
loadLocalParam(source.spend.path, source.spend.sha256, 'spend', source.source),
|
|
3040
|
+
loadLocalParam(source.output.path, source.output.sha256, 'output', source.source),
|
|
3041
|
+
]);
|
|
3042
|
+
return { spend, output };
|
|
3043
|
+
}
|
|
3044
|
+
const [spend, output] = await Promise.all([
|
|
3045
|
+
loadRemoteParam(source.spend.url, source.spend.sha256, 'spend', source.source),
|
|
3046
|
+
loadRemoteParam(source.output.url, source.output.sha256, 'output', source.source),
|
|
3047
|
+
]);
|
|
3048
|
+
return { spend, output };
|
|
3049
|
+
}
|
|
3050
|
+
async function loadRemoteParam(url, expectedSha256, label, source) {
|
|
3051
|
+
let response;
|
|
3052
|
+
try {
|
|
3053
|
+
response = await fetch(url);
|
|
3054
|
+
}
|
|
3055
|
+
catch (error) {
|
|
3056
|
+
throw new SaplingParamsError('SAPLING_PARAMS_FETCH_FAILED', `Failed to fetch Sapling ${label} params from ${url}`, source, error);
|
|
3057
|
+
}
|
|
3058
|
+
if (!response.ok) {
|
|
3059
|
+
throw new SaplingParamsError('SAPLING_PARAMS_FETCH_FAILED', `Failed to fetch Sapling ${label} params from ${url}: ${response.status}`, source);
|
|
3060
|
+
}
|
|
3061
|
+
const bytes = bufferExports.Buffer.from(await response.arrayBuffer());
|
|
3062
|
+
await assertSha256(bytes, expectedSha256, label, source, url);
|
|
3063
|
+
return bytes;
|
|
3064
|
+
}
|
|
3065
|
+
async function loadLocalParam(path, expectedSha256, label, source) {
|
|
3066
|
+
if (!isNodeLikeRuntime()) {
|
|
3067
|
+
throw new SaplingParamsError('SAPLING_PARAMS_UNSUPPORTED_RUNTIME', `Sapling local ${label} params are only supported in Node.js and CI environments`, source);
|
|
3068
|
+
}
|
|
3069
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
3070
|
+
const { readFile } = require(getNodeFsPromisesModuleId());
|
|
3071
|
+
const bytes = bufferExports.Buffer.from(await readFile(path));
|
|
3072
|
+
if (expectedSha256) {
|
|
3073
|
+
await assertSha256(bytes, expectedSha256, label, source, path);
|
|
3074
|
+
}
|
|
3075
|
+
return bytes;
|
|
3076
|
+
}
|
|
3077
|
+
async function assertSha256(bytes, expectedSha256, label, source, location) {
|
|
3078
|
+
const subtle = globalThis.crypto?.subtle;
|
|
3079
|
+
if (!subtle) {
|
|
3080
|
+
throw new SaplingParamsError('SAPLING_PARAMS_UNSUPPORTED_RUNTIME', `Sapling ${label} params verification requires globalThis.crypto.subtle`, source);
|
|
3081
|
+
}
|
|
3082
|
+
const digest = await subtle.digest('SHA-256', Uint8Array.from(bytes));
|
|
3083
|
+
const actualSha256 = bufferExports.Buffer.from(digest).toString('hex');
|
|
3084
|
+
if (actualSha256 !== expectedSha256) {
|
|
3085
|
+
throw new SaplingParamsError('SAPLING_PARAMS_HASH_MISMATCH', `Sapling ${label} params from ${source} failed integrity verification for ${location} (expected SHA-256 ${expectedSha256}, got ${actualSha256})`, source);
|
|
3086
|
+
}
|
|
3087
|
+
}
|
|
3088
|
+
function resolveSaplingParamsSource(params = undefined) {
|
|
3089
|
+
if (!params || typeof params.source !== 'undefined') {
|
|
3090
|
+
const source = params?.source ?? 'taquito';
|
|
3091
|
+
return {
|
|
3092
|
+
kind: 'remote',
|
|
3093
|
+
source,
|
|
3094
|
+
spend: {
|
|
3095
|
+
url: source === 'zcash'
|
|
3096
|
+
? DEFAULT_SAPLING_PARAMS_MANIFEST.spendParams.zcashUrl
|
|
3097
|
+
: DEFAULT_SAPLING_PARAMS_MANIFEST.spendParams.taquitoUrl,
|
|
3098
|
+
sha256: DEFAULT_SAPLING_PARAMS_MANIFEST.spendParams.sha256,
|
|
3099
|
+
},
|
|
3100
|
+
output: {
|
|
3101
|
+
url: source === 'zcash'
|
|
3102
|
+
? DEFAULT_SAPLING_PARAMS_MANIFEST.outputParams.zcashUrl
|
|
3103
|
+
: DEFAULT_SAPLING_PARAMS_MANIFEST.outputParams.taquitoUrl,
|
|
3104
|
+
sha256: DEFAULT_SAPLING_PARAMS_MANIFEST.outputParams.sha256,
|
|
3105
|
+
},
|
|
3106
|
+
};
|
|
3107
|
+
}
|
|
3108
|
+
if ('spendParamsPath' in params || 'outputParamsPath' in params) {
|
|
3109
|
+
if (!params.spendParamsPath || !params.outputParamsPath) {
|
|
3110
|
+
throw new SaplingParamsError('SAPLING_PARAMS_INVALID_CONFIG', 'Sapling local params configuration requires both spendParamsPath and outputParamsPath', 'local');
|
|
3111
|
+
}
|
|
3112
|
+
return {
|
|
3113
|
+
kind: 'local',
|
|
3114
|
+
source: 'local',
|
|
3115
|
+
spend: {
|
|
3116
|
+
path: params.spendParamsPath,
|
|
3117
|
+
sha256: params.spendParamsSha256,
|
|
3118
|
+
},
|
|
3119
|
+
output: {
|
|
3120
|
+
path: params.outputParamsPath,
|
|
3121
|
+
sha256: params.outputParamsSha256,
|
|
3122
|
+
},
|
|
3123
|
+
};
|
|
3124
|
+
}
|
|
3125
|
+
if (!params.spendParamsUrl || !params.outputParamsUrl) {
|
|
3126
|
+
throw new SaplingParamsError('SAPLING_PARAMS_INVALID_CONFIG', 'Sapling remote params configuration requires both spendParamsUrl and outputParamsUrl', 'custom');
|
|
3127
|
+
}
|
|
3128
|
+
if (!params.spendParamsSha256 || !params.outputParamsSha256) {
|
|
3129
|
+
throw new SaplingParamsError('SAPLING_PARAMS_INVALID_CONFIG', 'Sapling remote params configuration requires explicit SHA-256 digests', 'custom');
|
|
3130
|
+
}
|
|
3131
|
+
return {
|
|
3132
|
+
kind: 'remote',
|
|
3133
|
+
source: 'custom',
|
|
3134
|
+
spend: {
|
|
3135
|
+
url: params.spendParamsUrl,
|
|
3136
|
+
sha256: params.spendParamsSha256,
|
|
3137
|
+
},
|
|
3138
|
+
output: {
|
|
3139
|
+
url: params.outputParamsUrl,
|
|
3140
|
+
sha256: params.outputParamsSha256,
|
|
3141
|
+
},
|
|
3142
|
+
};
|
|
3143
|
+
}
|
|
3144
|
+
function isNodeLikeRuntime() {
|
|
3145
|
+
const runtimeProcess = globalThis.process;
|
|
3146
|
+
return !!runtimeProcess?.versions?.node;
|
|
3147
|
+
}
|
|
3148
|
+
function getNodeFsPromisesModuleId() {
|
|
3149
|
+
// Keep this module id opaque enough that browser bundlers do not eagerly
|
|
3150
|
+
// try to resolve a Node-only dependency into the browser build.
|
|
3151
|
+
return ['node', 'fs', 'promises'].join(':').replace('fs:promises', 'fs/promises');
|
|
3152
|
+
}
|
|
3153
|
+
|
|
2978
3154
|
const getRandomValueSource = () => {
|
|
2979
3155
|
const crypto = globalThis.crypto;
|
|
2980
3156
|
if (!crypto?.getRandomValues) {
|
|
@@ -2984,7 +3160,7 @@
|
|
|
2984
3160
|
};
|
|
2985
3161
|
class SaplingWrapper {
|
|
2986
3162
|
async withProvingContext(action) {
|
|
2987
|
-
await
|
|
3163
|
+
await preloadSaplingParams();
|
|
2988
3164
|
return saplingWasm.withProvingContext(action);
|
|
2989
3165
|
}
|
|
2990
3166
|
getRandomBytes(length) {
|
|
@@ -3022,13 +3198,7 @@
|
|
|
3022
3198
|
return saplingWasm.createBindingSignature(saplingContext, balance, transactionSigHash);
|
|
3023
3199
|
}
|
|
3024
3200
|
async initSaplingParameters() {
|
|
3025
|
-
|
|
3026
|
-
cachedParams = {
|
|
3027
|
-
spend: bufferExports.Buffer.from(saplingSpendParams.saplingSpendParams, 'base64'),
|
|
3028
|
-
output: bufferExports.Buffer.from(saplingOutputParams.saplingOutputParams, 'base64'),
|
|
3029
|
-
};
|
|
3030
|
-
}
|
|
3031
|
-
return saplingWasm.initParameters(cachedParams.spend, cachedParams.output);
|
|
3201
|
+
return preloadSaplingParams();
|
|
3032
3202
|
}
|
|
3033
3203
|
}
|
|
3034
3204
|
|
|
@@ -4420,8 +4590,11 @@
|
|
|
4420
4590
|
exports.InMemoryProvingKey = InMemoryProvingKey;
|
|
4421
4591
|
exports.InMemorySpendingKey = InMemorySpendingKey;
|
|
4422
4592
|
exports.InMemoryViewingKey = InMemoryViewingKey;
|
|
4593
|
+
exports.SaplingParamsError = SaplingParamsError;
|
|
4423
4594
|
exports.SaplingToolkit = SaplingToolkit;
|
|
4424
4595
|
exports.SaplingTransactionViewer = SaplingTransactionViewer;
|
|
4596
|
+
exports.initSapling = initSapling;
|
|
4597
|
+
exports.preloadSaplingParams = preloadSaplingParams;
|
|
4425
4598
|
|
|
4426
4599
|
}));
|
|
4427
4600
|
//# sourceMappingURL=taquito-sapling.umd.js.map
|