@taquito/sapling 17.3.2 → 17.4.0-beta-RC.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.
Files changed (53) hide show
  1. package/dist/lib/constants.js +0 -1
  2. package/dist/lib/errors.js +0 -1
  3. package/dist/lib/sapling-forger/sapling-forger.js +8 -9
  4. package/dist/lib/sapling-keys/helpers.js +6 -7
  5. package/dist/lib/sapling-keys/in-memory-proving-key.js +15 -18
  6. package/dist/lib/sapling-keys/in-memory-spending-key.js +22 -25
  7. package/dist/lib/sapling-keys/in-memory-viewing-key.js +18 -21
  8. package/dist/lib/sapling-module-wrapper.js +1 -2
  9. package/dist/lib/sapling-state/sapling-state.js +6 -7
  10. package/dist/lib/sapling-state/utils.js +0 -1
  11. package/dist/lib/sapling-tx-builder/sapling-transactions-builder.js +78 -80
  12. package/dist/lib/sapling-tx-viewer/helpers.js +2 -3
  13. package/dist/lib/sapling-tx-viewer/sapling-transaction-viewer.js +36 -39
  14. package/dist/lib/taquito-sapling.js +55 -58
  15. package/dist/lib/types.js +0 -1
  16. package/dist/lib/version.js +2 -3
  17. package/dist/taquito-sapling.es6.js +1383 -1380
  18. package/dist/taquito-sapling.es6.js.map +1 -1
  19. package/dist/taquito-sapling.umd.js +1387 -1393
  20. package/dist/taquito-sapling.umd.js.map +1 -1
  21. package/dist/types/constants.d.ts +5 -5
  22. package/dist/types/errors.d.ts +52 -52
  23. package/dist/types/sapling-forger/sapling-forger.d.ts +30 -30
  24. package/dist/types/sapling-keys/helpers.d.ts +2 -2
  25. package/dist/types/sapling-keys/in-memory-proving-key.d.ts +35 -35
  26. package/dist/types/sapling-keys/in-memory-spending-key.d.ts +53 -53
  27. package/dist/types/sapling-keys/in-memory-viewing-key.d.ts +48 -48
  28. package/dist/types/sapling-module-wrapper.d.ts +19 -19
  29. package/dist/types/sapling-state/sapling-state.d.ts +56 -56
  30. package/dist/types/sapling-state/utils.d.ts +22 -22
  31. package/dist/types/sapling-tx-builder/sapling-transactions-builder.d.ts +32 -32
  32. package/dist/types/sapling-tx-viewer/helpers.d.ts +11 -11
  33. package/dist/types/sapling-tx-viewer/sapling-transaction-viewer.d.ts +50 -50
  34. package/dist/types/taquito-sapling.d.ts +81 -81
  35. package/dist/types/types.d.ts +147 -147
  36. package/dist/types/version.d.ts +4 -4
  37. package/package.json +33 -35
  38. package/dist/lib/constants.js.map +0 -1
  39. package/dist/lib/errors.js.map +0 -1
  40. package/dist/lib/sapling-forger/sapling-forger.js.map +0 -1
  41. package/dist/lib/sapling-keys/helpers.js.map +0 -1
  42. package/dist/lib/sapling-keys/in-memory-proving-key.js.map +0 -1
  43. package/dist/lib/sapling-keys/in-memory-spending-key.js.map +0 -1
  44. package/dist/lib/sapling-keys/in-memory-viewing-key.js.map +0 -1
  45. package/dist/lib/sapling-module-wrapper.js.map +0 -1
  46. package/dist/lib/sapling-state/sapling-state.js.map +0 -1
  47. package/dist/lib/sapling-state/utils.js.map +0 -1
  48. package/dist/lib/sapling-tx-builder/sapling-transactions-builder.js.map +0 -1
  49. package/dist/lib/sapling-tx-viewer/helpers.js.map +0 -1
  50. package/dist/lib/sapling-tx-viewer/sapling-transaction-viewer.js.map +0 -1
  51. package/dist/lib/taquito-sapling.js.map +0 -1
  52. package/dist/lib/types.js.map +0 -1
  53. package/dist/lib/version.js.map +0 -1
@@ -8,20 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
12
- if (!privateMap.has(receiver)) {
13
- throw new TypeError("attempted to set private field on non-instance");
14
- }
15
- privateMap.set(receiver, value);
16
- return value;
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
17
16
  };
18
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
19
- if (!privateMap.has(receiver)) {
20
- throw new TypeError("attempted to get private field on non-instance");
21
- }
22
- return privateMap.get(receiver);
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
20
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
23
21
  };
24
- var _inMemorySpendingKey, _inMemoryProvingKey, _saplingForger, _contractAddress, _saplingId, _memoSize, _readProvider, _saplingWrapper, _chainId, _saplingState;
22
+ var _SaplingTransactionBuilder_inMemorySpendingKey, _SaplingTransactionBuilder_inMemoryProvingKey, _SaplingTransactionBuilder_saplingForger, _SaplingTransactionBuilder_contractAddress, _SaplingTransactionBuilder_saplingId, _SaplingTransactionBuilder_memoSize, _SaplingTransactionBuilder_readProvider, _SaplingTransactionBuilder_saplingWrapper, _SaplingTransactionBuilder_chainId, _SaplingTransactionBuilder_saplingState;
25
23
  Object.defineProperty(exports, "__esModule", { value: true });
26
24
  exports.SaplingTransactionBuilder = void 0;
27
25
  const blakejs_1 = require("blakejs");
@@ -34,37 +32,37 @@ const sapling_state_1 = require("../sapling-state/sapling-state");
34
32
  const sapling_module_wrapper_1 = require("../sapling-module-wrapper");
35
33
  class SaplingTransactionBuilder {
36
34
  constructor(keys, saplingForger, saplingContractDetails, readProvider, saplingWrapper = new sapling_module_wrapper_1.SaplingWrapper()) {
37
- _inMemorySpendingKey.set(this, void 0);
38
- _inMemoryProvingKey.set(this, void 0);
39
- _saplingForger.set(this, void 0);
40
- _contractAddress.set(this, void 0);
41
- _saplingId.set(this, void 0);
42
- _memoSize.set(this, void 0);
43
- _readProvider.set(this, void 0);
44
- _saplingWrapper.set(this, void 0);
45
- _chainId.set(this, void 0);
46
- _saplingState.set(this, void 0);
47
- __classPrivateFieldSet(this, _saplingForger, saplingForger);
48
- __classPrivateFieldSet(this, _contractAddress, saplingContractDetails.contractAddress);
49
- __classPrivateFieldSet(this, _memoSize, saplingContractDetails.memoSize);
50
- __classPrivateFieldSet(this, _inMemorySpendingKey, keys.saplingSigner);
51
- __classPrivateFieldSet(this, _inMemoryProvingKey, keys.saplingProver);
52
- __classPrivateFieldSet(this, _saplingState, new sapling_state_1.SaplingState(32));
53
- __classPrivateFieldSet(this, _saplingId, saplingContractDetails.saplingId);
54
- __classPrivateFieldSet(this, _saplingWrapper, saplingWrapper);
55
- __classPrivateFieldSet(this, _readProvider, readProvider);
35
+ _SaplingTransactionBuilder_inMemorySpendingKey.set(this, void 0);
36
+ _SaplingTransactionBuilder_inMemoryProvingKey.set(this, void 0);
37
+ _SaplingTransactionBuilder_saplingForger.set(this, void 0);
38
+ _SaplingTransactionBuilder_contractAddress.set(this, void 0);
39
+ _SaplingTransactionBuilder_saplingId.set(this, void 0);
40
+ _SaplingTransactionBuilder_memoSize.set(this, void 0);
41
+ _SaplingTransactionBuilder_readProvider.set(this, void 0);
42
+ _SaplingTransactionBuilder_saplingWrapper.set(this, void 0);
43
+ _SaplingTransactionBuilder_chainId.set(this, void 0);
44
+ _SaplingTransactionBuilder_saplingState.set(this, void 0);
45
+ __classPrivateFieldSet(this, _SaplingTransactionBuilder_saplingForger, saplingForger, "f");
46
+ __classPrivateFieldSet(this, _SaplingTransactionBuilder_contractAddress, saplingContractDetails.contractAddress, "f");
47
+ __classPrivateFieldSet(this, _SaplingTransactionBuilder_memoSize, saplingContractDetails.memoSize, "f");
48
+ __classPrivateFieldSet(this, _SaplingTransactionBuilder_inMemorySpendingKey, keys.saplingSigner, "f");
49
+ __classPrivateFieldSet(this, _SaplingTransactionBuilder_inMemoryProvingKey, keys.saplingProver, "f");
50
+ __classPrivateFieldSet(this, _SaplingTransactionBuilder_saplingState, new sapling_state_1.SaplingState(32), "f");
51
+ __classPrivateFieldSet(this, _SaplingTransactionBuilder_saplingId, saplingContractDetails.saplingId, "f");
52
+ __classPrivateFieldSet(this, _SaplingTransactionBuilder_saplingWrapper, saplingWrapper, "f");
53
+ __classPrivateFieldSet(this, _SaplingTransactionBuilder_readProvider, readProvider, "f");
56
54
  }
57
55
  createShieldedTx(saplingTransactionParams, txTotalAmount, boundData) {
58
56
  return __awaiter(this, void 0, void 0, function* () {
59
- const rcm = yield __classPrivateFieldGet(this, _saplingWrapper).randR();
57
+ const rcm = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").randR();
60
58
  const balance = this.calculateTransactionBalance('0', txTotalAmount.toString());
61
- const { signature, inputs, outputs } = yield __classPrivateFieldGet(this, _saplingWrapper).withProvingContext((saplingContext) => __awaiter(this, void 0, void 0, function* () {
59
+ const { signature, inputs, outputs } = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").withProvingContext((saplingContext) => __awaiter(this, void 0, void 0, function* () {
62
60
  const outputs = [];
63
61
  const inputs = [];
64
62
  for (const i in saplingTransactionParams) {
65
63
  outputs.push(yield this.prepareSaplingOutputDescription({
66
64
  saplingContext,
67
- address: utils_1.b58cdecode(saplingTransactionParams[i].to, utils_1.prefix[utils_1.Prefix.ZET1]),
65
+ address: (0, utils_1.b58cdecode)(saplingTransactionParams[i].to, utils_1.prefix[utils_1.Prefix.ZET1]),
68
66
  amount: saplingTransactionParams[i].amount,
69
67
  memo: saplingTransactionParams[i].memo,
70
68
  randomCommitmentTrapdoor: rcm,
@@ -89,10 +87,10 @@ class SaplingTransactionBuilder {
89
87
  }
90
88
  createSaplingTx(saplingTransactionParams, txTotalAmount, boundData, chosenInputs) {
91
89
  return __awaiter(this, void 0, void 0, function* () {
92
- const randomCommitmentTrapdoor = yield __classPrivateFieldGet(this, _saplingWrapper).randR();
93
- const saplingViewer = yield __classPrivateFieldGet(this, _inMemorySpendingKey).getSaplingViewingKeyProvider();
90
+ const randomCommitmentTrapdoor = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").randR();
91
+ const saplingViewer = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_inMemorySpendingKey, "f").getSaplingViewingKeyProvider();
94
92
  const outgoingViewingKey = yield saplingViewer.getOutgoingViewingKey();
95
- const { signature, balance, inputs, outputs } = yield __classPrivateFieldGet(this, _saplingWrapper).withProvingContext((saplingContext) => __awaiter(this, void 0, void 0, function* () {
93
+ const { signature, balance, inputs, outputs } = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").withProvingContext((saplingContext) => __awaiter(this, void 0, void 0, function* () {
96
94
  const outputs = [];
97
95
  const inputs = [];
98
96
  inputs.push(...(yield this.prepareSaplingSpendDescription(saplingContext, chosenInputs.inputsToSpend)));
@@ -101,7 +99,7 @@ class SaplingTransactionBuilder {
101
99
  sumAmountOutput = sumAmountOutput.plus(new bignumber_js_1.default(saplingTransactionParams[i].amount));
102
100
  outputs.push(yield this.prepareSaplingOutputDescription({
103
101
  saplingContext,
104
- address: utils_1.b58cdecode(saplingTransactionParams[i].to, utils_1.prefix[utils_1.Prefix.ZET1]),
102
+ address: (0, utils_1.b58cdecode)(saplingTransactionParams[i].to, utils_1.prefix[utils_1.Prefix.ZET1]),
105
103
  amount: saplingTransactionParams[i].amount,
106
104
  memo: saplingTransactionParams[i].memo,
107
105
  randomCommitmentTrapdoor,
@@ -112,7 +110,7 @@ class SaplingTransactionBuilder {
112
110
  const payBackAddress = (yield saplingViewer.getAddress()).address;
113
111
  const { payBackOutput, payBackAmount } = yield this.createPaybackOutput({
114
112
  saplingContext,
115
- address: utils_1.b58cdecode(payBackAddress, utils_1.prefix[utils_1.Prefix.ZET1]),
113
+ address: (0, utils_1.b58cdecode)(payBackAddress, utils_1.prefix[utils_1.Prefix.ZET1]),
116
114
  amount: txTotalAmount.toString(),
117
115
  memo: constants_1.DEFAULT_MEMO,
118
116
  randomCommitmentTrapdoor: randomCommitmentTrapdoor,
@@ -145,16 +143,16 @@ class SaplingTransactionBuilder {
145
143
  }
146
144
  prepareSaplingOutputDescription(parametersOutputDescription) {
147
145
  return __awaiter(this, void 0, void 0, function* () {
148
- const ephemeralPrivateKey = yield __classPrivateFieldGet(this, _saplingWrapper).randR();
149
- const { commitmentValue, commitment, proof } = yield __classPrivateFieldGet(this, _saplingWrapper).preparePartialOutputDescription({
146
+ const ephemeralPrivateKey = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").randR();
147
+ const { commitmentValue, commitment, proof } = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").preparePartialOutputDescription({
150
148
  saplingContext: parametersOutputDescription.saplingContext,
151
149
  address: parametersOutputDescription.address,
152
150
  randomCommitmentTrapdoor: parametersOutputDescription.randomCommitmentTrapdoor,
153
151
  ephemeralPrivateKey,
154
152
  amount: parametersOutputDescription.amount,
155
153
  });
156
- const diversifier = yield __classPrivateFieldGet(this, _saplingWrapper).getDiversifiedFromRawPaymentAddress(parametersOutputDescription.address);
157
- const ephemeralPublicKey = yield __classPrivateFieldGet(this, _saplingWrapper).deriveEphemeralPublicKey(diversifier, ephemeralPrivateKey);
154
+ const diversifier = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").getDiversifiedFromRawPaymentAddress(parametersOutputDescription.address);
155
+ const ephemeralPublicKey = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").deriveEphemeralPublicKey(diversifier, ephemeralPrivateKey);
158
156
  const outgoingCipherKey = parametersOutputDescription.outgoingViewingKey
159
157
  ? blakejs_1.default.blake2b(Buffer.concat([
160
158
  commitmentValue,
@@ -162,7 +160,7 @@ class SaplingTransactionBuilder {
162
160
  ephemeralPublicKey,
163
161
  parametersOutputDescription.outgoingViewingKey,
164
162
  ]), Buffer.from(constants_1.OCK_KEY), 32)
165
- : __classPrivateFieldGet(this, _saplingWrapper).getRandomBytes(32);
163
+ : __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").getRandomBytes(32);
166
164
  const ciphertext = yield this.encryptCiphertext({
167
165
  address: parametersOutputDescription.address,
168
166
  ephemeralPrivateKey,
@@ -182,29 +180,30 @@ class SaplingTransactionBuilder {
182
180
  }
183
181
  prepareSaplingSpendDescription(saplingContext, inputsToSpend) {
184
182
  return __awaiter(this, void 0, void 0, function* () {
185
- const publicKeyReRandomization = yield __classPrivateFieldGet(this, _saplingWrapper).randR();
183
+ const publicKeyReRandomization = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").randR();
186
184
  let stateDiff;
187
- if (__classPrivateFieldGet(this, _saplingId)) {
188
- stateDiff = yield __classPrivateFieldGet(this, _readProvider).getSaplingDiffById({ id: __classPrivateFieldGet(this, _saplingId) }, 'head');
185
+ if (__classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingId, "f")) {
186
+ stateDiff = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_readProvider, "f").getSaplingDiffById({ id: __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingId, "f") }, 'head');
189
187
  }
190
188
  else {
191
- stateDiff = yield __classPrivateFieldGet(this, _readProvider).getSaplingDiffByContract(__classPrivateFieldGet(this, _contractAddress), 'head');
189
+ stateDiff = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_readProvider, "f").getSaplingDiffByContract(__classPrivateFieldGet(this, _SaplingTransactionBuilder_contractAddress, "f"), 'head');
192
190
  }
193
- const stateTree = yield __classPrivateFieldGet(this, _saplingState).getStateTree(stateDiff, true);
191
+ const stateTree = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingState, "f").getStateTree(stateDiff, true);
194
192
  const saplingSpendDescriptions = [];
195
193
  for (let i = 0; i < inputsToSpend.length; i++) {
196
- const amount = helpers_1.convertValueToBigNumber(inputsToSpend[i].value).toString();
197
- const witness = yield __classPrivateFieldGet(this, _saplingState).getWitness(stateTree, new bignumber_js_1.default(inputsToSpend[i].position));
198
- const unsignedSpendDescription = __classPrivateFieldGet(this, _inMemoryProvingKey) ? yield __classPrivateFieldGet(this, _inMemoryProvingKey).prepareSpendDescription({
199
- saplingContext,
200
- address: inputsToSpend[i].paymentAddress,
201
- randomCommitmentTrapdoor: inputsToSpend[i].randomCommitmentTrapdoor,
202
- publicKeyReRandomization,
203
- amount,
204
- root: stateDiff.root,
205
- witness,
206
- })
207
- : yield __classPrivateFieldGet(this, _inMemorySpendingKey).prepareSpendDescription({
194
+ const amount = (0, helpers_1.convertValueToBigNumber)(inputsToSpend[i].value).toString();
195
+ const witness = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingState, "f").getWitness(stateTree, new bignumber_js_1.default(inputsToSpend[i].position));
196
+ const unsignedSpendDescription = __classPrivateFieldGet(this, _SaplingTransactionBuilder_inMemoryProvingKey, "f")
197
+ ? yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_inMemoryProvingKey, "f").prepareSpendDescription({
198
+ saplingContext,
199
+ address: inputsToSpend[i].paymentAddress,
200
+ randomCommitmentTrapdoor: inputsToSpend[i].randomCommitmentTrapdoor,
201
+ publicKeyReRandomization,
202
+ amount,
203
+ root: stateDiff.root,
204
+ witness,
205
+ })
206
+ : yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_inMemorySpendingKey, "f").prepareSpendDescription({
208
207
  saplingContext,
209
208
  address: inputsToSpend[i].paymentAddress,
210
209
  randomCommitmentTrapdoor: inputsToSpend[i].randomCommitmentTrapdoor,
@@ -213,9 +212,9 @@ class SaplingTransactionBuilder {
213
212
  root: stateDiff.root,
214
213
  witness,
215
214
  });
216
- const unsignedSpendDescriptionBytes = __classPrivateFieldGet(this, _saplingForger).forgeUnsignedTxInput(unsignedSpendDescription);
215
+ const unsignedSpendDescriptionBytes = __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingForger, "f").forgeUnsignedTxInput(unsignedSpendDescription);
217
216
  const hash = blakejs_1.default.blake2b(unsignedSpendDescriptionBytes, yield this.getAntiReplay(), 32);
218
- const spendDescription = yield __classPrivateFieldGet(this, _inMemorySpendingKey).signSpendDescription({
217
+ const spendDescription = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_inMemorySpendingKey, "f").signSpendDescription({
219
218
  publicKeyReRandomization,
220
219
  unsignedSpendDescription,
221
220
  hash,
@@ -230,20 +229,20 @@ class SaplingTransactionBuilder {
230
229
  }
231
230
  encryptCiphertext(parametersCiphertext) {
232
231
  return __awaiter(this, void 0, void 0, function* () {
233
- const recipientDiversifiedTransmissionKey = yield __classPrivateFieldGet(this, _saplingWrapper).getPkdFromRawPaymentAddress(parametersCiphertext.address);
234
- const keyAgreement = yield __classPrivateFieldGet(this, _saplingWrapper).keyAgreement(recipientDiversifiedTransmissionKey, parametersCiphertext.ephemeralPrivateKey);
232
+ const recipientDiversifiedTransmissionKey = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").getPkdFromRawPaymentAddress(parametersCiphertext.address);
233
+ const keyAgreement = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").keyAgreement(recipientDiversifiedTransmissionKey, parametersCiphertext.ephemeralPrivateKey);
235
234
  const keyAgreementHash = blakejs_1.default.blake2b(keyAgreement, Buffer.from(constants_1.KDF_KEY), 32);
236
- const nonceEnc = Buffer.from(__classPrivateFieldGet(this, _saplingWrapper).getRandomBytes(24));
237
- const transactionPlaintext = __classPrivateFieldGet(this, _saplingForger).forgeTransactionPlaintext({
235
+ const nonceEnc = Buffer.from(__classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").getRandomBytes(24));
236
+ const transactionPlaintext = __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingForger, "f").forgeTransactionPlaintext({
238
237
  diversifier: parametersCiphertext.diversifier,
239
238
  amount: parametersCiphertext.amount,
240
239
  randomCommitmentTrapdoor: parametersCiphertext.randomCommitmentTrapdoor,
241
- memoSize: __classPrivateFieldGet(this, _memoSize) * 2,
240
+ memoSize: __classPrivateFieldGet(this, _SaplingTransactionBuilder_memoSize, "f") * 2,
242
241
  memo: parametersCiphertext.memo,
243
242
  });
244
- const nonceOut = Buffer.from(__classPrivateFieldGet(this, _saplingWrapper).getRandomBytes(24));
245
- const payloadEnc = Buffer.from(nacl_1.secretBox(keyAgreementHash, nonceEnc, transactionPlaintext));
246
- const payloadOut = Buffer.from(nacl_1.secretBox(parametersCiphertext.outgoingCipherKey, nonceOut, Buffer.concat([
243
+ const nonceOut = Buffer.from(__classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").getRandomBytes(24));
244
+ const payloadEnc = Buffer.from((0, nacl_1.secretBox)(keyAgreementHash, nonceEnc, transactionPlaintext));
245
+ const payloadOut = Buffer.from((0, nacl_1.secretBox)(parametersCiphertext.outgoingCipherKey, nonceOut, Buffer.concat([
247
246
  recipientDiversifiedTransmissionKey,
248
247
  parametersCiphertext.ephemeralPrivateKey,
249
248
  ])));
@@ -266,23 +265,22 @@ class SaplingTransactionBuilder {
266
265
  }
267
266
  createBindingSignature(parametersBindingSig) {
268
267
  return __awaiter(this, void 0, void 0, function* () {
269
- const outputs = __classPrivateFieldGet(this, _saplingForger).forgeOutputDescriptions(parametersBindingSig.outputs);
270
- const inputs = __classPrivateFieldGet(this, _saplingForger).forgeSpendDescriptions(parametersBindingSig.inputs);
268
+ const outputs = __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingForger, "f").forgeOutputDescriptions(parametersBindingSig.outputs);
269
+ const inputs = __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingForger, "f").forgeSpendDescriptions(parametersBindingSig.inputs);
271
270
  const transactionSigHash = blakejs_1.default.blake2b(Buffer.concat([inputs, outputs, parametersBindingSig.boundData]), yield this.getAntiReplay(), 32);
272
- return __classPrivateFieldGet(this, _saplingWrapper).createBindingSignature(parametersBindingSig.saplingContext, parametersBindingSig.balance.toFixed(), transactionSigHash);
271
+ return __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").createBindingSignature(parametersBindingSig.saplingContext, parametersBindingSig.balance.toFixed(), transactionSigHash);
273
272
  });
274
273
  }
275
274
  getAntiReplay() {
276
275
  return __awaiter(this, void 0, void 0, function* () {
277
- let chainId = __classPrivateFieldGet(this, _chainId);
276
+ let chainId = __classPrivateFieldGet(this, _SaplingTransactionBuilder_chainId, "f");
278
277
  if (!chainId) {
279
- chainId = yield __classPrivateFieldGet(this, _readProvider).getChainId();
280
- __classPrivateFieldSet(this, _chainId, chainId);
278
+ chainId = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_readProvider, "f").getChainId();
279
+ __classPrivateFieldSet(this, _SaplingTransactionBuilder_chainId, chainId, "f");
281
280
  }
282
- return Buffer.from(`${__classPrivateFieldGet(this, _contractAddress)}${chainId}`);
281
+ return Buffer.from(`${__classPrivateFieldGet(this, _SaplingTransactionBuilder_contractAddress, "f")}${chainId}`);
283
282
  });
284
283
  }
285
284
  }
286
285
  exports.SaplingTransactionBuilder = SaplingTransactionBuilder;
287
- _inMemorySpendingKey = new WeakMap(), _inMemoryProvingKey = new WeakMap(), _saplingForger = new WeakMap(), _contractAddress = new WeakMap(), _saplingId = new WeakMap(), _memoSize = new WeakMap(), _readProvider = new WeakMap(), _saplingWrapper = new WeakMap(), _chainId = new WeakMap(), _saplingState = new WeakMap();
288
- //# sourceMappingURL=sapling-transactions-builder.js.map
286
+ _SaplingTransactionBuilder_inMemorySpendingKey = new WeakMap(), _SaplingTransactionBuilder_inMemoryProvingKey = new WeakMap(), _SaplingTransactionBuilder_saplingForger = new WeakMap(), _SaplingTransactionBuilder_contractAddress = new WeakMap(), _SaplingTransactionBuilder_saplingId = new WeakMap(), _SaplingTransactionBuilder_memoSize = new WeakMap(), _SaplingTransactionBuilder_readProvider = new WeakMap(), _SaplingTransactionBuilder_saplingWrapper = new WeakMap(), _SaplingTransactionBuilder_chainId = new WeakMap(), _SaplingTransactionBuilder_saplingState = new WeakMap();
@@ -5,7 +5,7 @@ const utils_1 = require("@taquito/utils");
5
5
  const bignumber_js_1 = require("bignumber.js");
6
6
  function memoHexToUtf8(memo) {
7
7
  const memoNoPadding = removeZeroPaddedBytesRight(memo);
8
- return memoNoPadding === '' ? memoNoPadding : utils_1.bytes2Char(memoNoPadding);
8
+ return memoNoPadding === '' ? memoNoPadding : (0, utils_1.bytes2Char)(memoNoPadding);
9
9
  }
10
10
  exports.memoHexToUtf8 = memoHexToUtf8;
11
11
  function removeZeroPaddedBytesRight(memo) {
@@ -16,7 +16,7 @@ function readableFormat(saplingTransactionProperties) {
16
16
  return {
17
17
  value: convertValueToBigNumber(saplingTransactionProperties.value),
18
18
  memo: memoHexToUtf8(Buffer.from(saplingTransactionProperties.memo).toString('hex')),
19
- paymentAddress: utils_1.b58cencode(saplingTransactionProperties.paymentAddress, utils_1.prefix[utils_1.Prefix.ZET1]),
19
+ paymentAddress: (0, utils_1.b58cencode)(saplingTransactionProperties.paymentAddress, utils_1.prefix[utils_1.Prefix.ZET1]),
20
20
  };
21
21
  }
22
22
  exports.readableFormat = readableFormat;
@@ -28,4 +28,3 @@ function bufToUint8Array(buffer) {
28
28
  return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / Uint8Array.BYTES_PER_ELEMENT);
29
29
  }
30
30
  exports.bufToUint8Array = bufToUint8Array;
31
- //# sourceMappingURL=helpers.js.map
@@ -8,18 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
12
- if (!privateMap.has(receiver)) {
13
- throw new TypeError("attempted to set private field on non-instance");
14
- }
15
- privateMap.set(receiver, value);
16
- return value;
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
17
16
  };
18
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
19
- if (!privateMap.has(receiver)) {
20
- throw new TypeError("attempted to get private field on non-instance");
21
- }
22
- return privateMap.get(receiver);
17
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
20
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
23
21
  };
24
22
  var __rest = (this && this.__rest) || function (s, e) {
25
23
  var t = {};
@@ -32,7 +30,7 @@ var __rest = (this && this.__rest) || function (s, e) {
32
30
  }
33
31
  return t;
34
32
  };
35
- var _viewingKeyProvider, _readProvider, _saplingContractId;
33
+ var _SaplingTransactionViewer_viewingKeyProvider, _SaplingTransactionViewer_readProvider, _SaplingTransactionViewer_saplingContractId;
36
34
  Object.defineProperty(exports, "__esModule", { value: true });
37
35
  exports.SaplingTransactionViewer = void 0;
38
36
  const sapling = require("@airgap/sapling-wasm");
@@ -52,12 +50,12 @@ const errors_1 = require("../errors");
52
50
  */
53
51
  class SaplingTransactionViewer {
54
52
  constructor(inMemoryViewingKey, saplingContractId, readProvider) {
55
- _viewingKeyProvider.set(this, void 0);
56
- _readProvider.set(this, void 0);
57
- _saplingContractId.set(this, void 0);
58
- __classPrivateFieldSet(this, _viewingKeyProvider, inMemoryViewingKey);
59
- __classPrivateFieldSet(this, _saplingContractId, saplingContractId);
60
- __classPrivateFieldSet(this, _readProvider, readProvider);
53
+ _SaplingTransactionViewer_viewingKeyProvider.set(this, void 0);
54
+ _SaplingTransactionViewer_readProvider.set(this, void 0);
55
+ _SaplingTransactionViewer_saplingContractId.set(this, void 0);
56
+ __classPrivateFieldSet(this, _SaplingTransactionViewer_viewingKeyProvider, inMemoryViewingKey, "f");
57
+ __classPrivateFieldSet(this, _SaplingTransactionViewer_saplingContractId, saplingContractId, "f");
58
+ __classPrivateFieldSet(this, _SaplingTransactionViewer_readProvider, readProvider, "f");
61
59
  }
62
60
  /**
63
61
  * @description Retrieve the unspent balance associated with the configured viewing key and sapling state
@@ -72,7 +70,7 @@ class SaplingTransactionViewer {
72
70
  for (let i = 0; i < commitments_and_ciphertexts.length; i++) {
73
71
  const decrypted = yield this.decryptCiphertextAsReceiver(commitments_and_ciphertexts[i]);
74
72
  if (decrypted) {
75
- const valueBigNumber = helpers_1.convertValueToBigNumber(decrypted.value);
73
+ const valueBigNumber = (0, helpers_1.convertValueToBigNumber)(decrypted.value);
76
74
  const isSpent = yield this.isSpent(decrypted.paymentAddress, valueBigNumber.toString(), decrypted.randomCommitmentTrapdoor, i, nullifiers);
77
75
  if (!isSpent) {
78
76
  balance = balance.plus(valueBigNumber);
@@ -96,7 +94,7 @@ class SaplingTransactionViewer {
96
94
  const decryptedAsReceiver = yield this.decryptCiphertextAsReceiver(commitments_and_ciphertexts[i]);
97
95
  const decryptedAsSender = yield this.decryptCiphertextAsSender(commitments_and_ciphertexts[i]);
98
96
  if (decryptedAsReceiver) {
99
- const balance = helpers_1.convertValueToBigNumber(decryptedAsReceiver.value);
97
+ const balance = (0, helpers_1.convertValueToBigNumber)(decryptedAsReceiver.value);
100
98
  const isSpent = yield this.isSpent(decryptedAsReceiver.paymentAddress, balance.toString(), decryptedAsReceiver.randomCommitmentTrapdoor, i, nullifiers);
101
99
  incoming.push(Object.assign(Object.assign({}, decryptedAsReceiver), { isSpent, position: i }));
102
100
  }
@@ -119,10 +117,10 @@ class SaplingTransactionViewer {
119
117
  const tx = yield this.getIncomingAndOutgoingTransactionsRaw();
120
118
  const incoming = tx.incoming.map((_a) => {
121
119
  var { isSpent } = _a, rest = __rest(_a, ["isSpent"]);
122
- return Object.assign(Object.assign({}, helpers_1.readableFormat(rest)), { isSpent });
120
+ return Object.assign(Object.assign({}, (0, helpers_1.readableFormat)(rest)), { isSpent });
123
121
  });
124
122
  const outgoing = tx.outgoing.map((outgoingTx) => {
125
- return helpers_1.readableFormat(outgoingTx);
123
+ return (0, helpers_1.readableFormat)(outgoingTx);
126
124
  });
127
125
  return { incoming, outgoing };
128
126
  });
@@ -130,11 +128,11 @@ class SaplingTransactionViewer {
130
128
  getSaplingDiff() {
131
129
  return __awaiter(this, void 0, void 0, function* () {
132
130
  let saplingDiffResponse;
133
- if (__classPrivateFieldGet(this, _saplingContractId).saplingId) {
134
- saplingDiffResponse = yield __classPrivateFieldGet(this, _readProvider).getSaplingDiffById({ id: __classPrivateFieldGet(this, _saplingContractId).saplingId }, 'head');
131
+ if (__classPrivateFieldGet(this, _SaplingTransactionViewer_saplingContractId, "f").saplingId) {
132
+ saplingDiffResponse = yield __classPrivateFieldGet(this, _SaplingTransactionViewer_readProvider, "f").getSaplingDiffById({ id: __classPrivateFieldGet(this, _SaplingTransactionViewer_saplingContractId, "f").saplingId }, 'head');
135
133
  }
136
- else if (__classPrivateFieldGet(this, _saplingContractId).contractAddress) {
137
- saplingDiffResponse = yield __classPrivateFieldGet(this, _readProvider).getSaplingDiffByContract(__classPrivateFieldGet(this, _saplingContractId).contractAddress, 'head');
134
+ else if (__classPrivateFieldGet(this, _SaplingTransactionViewer_saplingContractId, "f").contractAddress) {
135
+ saplingDiffResponse = yield __classPrivateFieldGet(this, _SaplingTransactionViewer_readProvider, "f").getSaplingDiffByContract(__classPrivateFieldGet(this, _SaplingTransactionViewer_saplingContractId, "f").contractAddress, 'head');
138
136
  }
139
137
  else {
140
138
  throw new errors_1.SaplingTransactionViewerError('A contract address or a sapling id was expected in the SaplingTransactionViewer constructor.');
@@ -146,15 +144,15 @@ class SaplingTransactionViewer {
146
144
  return __awaiter(this, void 0, void 0, function* () {
147
145
  const commitment = commitmentsAndCiphertexts[0];
148
146
  const { epk, payload_enc, nonce_enc } = commitmentsAndCiphertexts[1];
149
- const incomingViewingKey = yield __classPrivateFieldGet(this, _viewingKeyProvider).getIncomingViewingKey();
147
+ const incomingViewingKey = yield __classPrivateFieldGet(this, _SaplingTransactionViewer_viewingKeyProvider, "f").getIncomingViewingKey();
150
148
  const keyAgreement = yield sapling.keyAgreement(epk, incomingViewingKey);
151
149
  const keyAgreementHash = blakejs_1.default.blake2b(keyAgreement, Buffer.from(constants_1.KDF_KEY), 32);
152
- const decrypted = yield this.decryptCiphertext(keyAgreementHash, utils_1.hex2buf(nonce_enc), utils_1.hex2buf(payload_enc));
150
+ const decrypted = yield this.decryptCiphertext(keyAgreementHash, (0, utils_1.hex2buf)(nonce_enc), (0, utils_1.hex2buf)(payload_enc));
153
151
  if (decrypted) {
154
152
  const { diversifier, value, randomCommitmentTrapdoor: rcm, memo, } = this.extractTransactionProperties(decrypted);
155
- const paymentAddress = helpers_1.bufToUint8Array(yield sapling.getRawPaymentAddressFromIncomingViewingKey(incomingViewingKey, diversifier));
153
+ const paymentAddress = (0, helpers_1.bufToUint8Array)(yield sapling.getRawPaymentAddressFromIncomingViewingKey(incomingViewingKey, diversifier));
156
154
  try {
157
- const valid = yield sapling.verifyCommitment(commitment, paymentAddress, helpers_1.convertValueToBigNumber(value).toString(), rcm);
155
+ const valid = yield sapling.verifyCommitment(commitment, paymentAddress, (0, helpers_1.convertValueToBigNumber)(value).toString(), rcm);
158
156
  if (valid) {
159
157
  return { value, memo, paymentAddress, randomCommitmentTrapdoor: rcm };
160
158
  }
@@ -171,20 +169,20 @@ class SaplingTransactionViewer {
171
169
  return __awaiter(this, void 0, void 0, function* () {
172
170
  const commitment = commitmentsAndCiphertexts[0];
173
171
  const { epk, payload_enc, nonce_enc, payload_out, nonce_out, cv } = commitmentsAndCiphertexts[1];
174
- const outgoingViewingKey = yield __classPrivateFieldGet(this, _viewingKeyProvider).getOutgoingViewingKey();
172
+ const outgoingViewingKey = yield __classPrivateFieldGet(this, _SaplingTransactionViewer_viewingKeyProvider, "f").getOutgoingViewingKey();
175
173
  const concat = cv.concat(commitment, epk, outgoingViewingKey.toString('hex'));
176
174
  const outgoingCipherKey = blakejs_1.default.blake2b(Buffer.from(concat, 'hex'), Buffer.from(constants_1.OCK_KEY), 32);
177
- const decryptedOut = yield this.decryptCiphertext(outgoingCipherKey, utils_1.hex2buf(nonce_out), utils_1.hex2buf(payload_out));
175
+ const decryptedOut = yield this.decryptCiphertext(outgoingCipherKey, (0, utils_1.hex2buf)(nonce_out), (0, utils_1.hex2buf)(payload_out));
178
176
  if (decryptedOut) {
179
177
  const { recipientDiversifiedTransmissionKey: pkd, ephemeralPrivateKey: esk } = this.extractPkdAndEsk(decryptedOut);
180
178
  const keyAgreement = yield sapling.keyAgreement(pkd, esk);
181
179
  const keyAgreementHash = blakejs_1.default.blake2b(keyAgreement, Buffer.from(constants_1.KDF_KEY), 32);
182
- const decryptedEnc = yield this.decryptCiphertext(keyAgreementHash, utils_1.hex2buf(nonce_enc), utils_1.hex2buf(payload_enc));
180
+ const decryptedEnc = yield this.decryptCiphertext(keyAgreementHash, (0, utils_1.hex2buf)(nonce_enc), (0, utils_1.hex2buf)(payload_enc));
183
181
  if (decryptedEnc) {
184
182
  const { diversifier, value, randomCommitmentTrapdoor: rcm, memo, } = this.extractTransactionProperties(decryptedEnc);
185
- const paymentAddress = utils_1.mergebuf(diversifier, pkd);
183
+ const paymentAddress = (0, utils_1.mergebuf)(diversifier, pkd);
186
184
  try {
187
- const isValid = yield sapling.verifyCommitment(commitment, paymentAddress, helpers_1.convertValueToBigNumber(value).toString(), rcm);
185
+ const isValid = yield sapling.verifyCommitment(commitment, paymentAddress, (0, helpers_1.convertValueToBigNumber)(value).toString(), rcm);
188
186
  if (isValid) {
189
187
  return { value, memo, paymentAddress, randomCommitmentTrapdoor: rcm };
190
188
  }
@@ -200,7 +198,7 @@ class SaplingTransactionViewer {
200
198
  }
201
199
  decryptCiphertext(keyAgreementHash, nonce, payload) {
202
200
  return __awaiter(this, void 0, void 0, function* () {
203
- return nacl_1.openSecretBox(keyAgreementHash, nonce, payload);
201
+ return (0, nacl_1.openSecretBox)(keyAgreementHash, nonce, payload);
204
202
  });
205
203
  }
206
204
  extractTransactionProperties(decrypted) {
@@ -220,11 +218,10 @@ class SaplingTransactionViewer {
220
218
  }
221
219
  isSpent(address, value, randomCommitmentTrapdoor, position, nullifiers) {
222
220
  return __awaiter(this, void 0, void 0, function* () {
223
- const computedNullifier = yield sapling.computeNullifier(__classPrivateFieldGet(this, _viewingKeyProvider).getFullViewingKey(), address, value, randomCommitmentTrapdoor, position);
221
+ const computedNullifier = yield sapling.computeNullifier(__classPrivateFieldGet(this, _SaplingTransactionViewer_viewingKeyProvider, "f").getFullViewingKey(), address, value, randomCommitmentTrapdoor, position);
224
222
  return nullifiers.includes(computedNullifier.toString('hex'));
225
223
  });
226
224
  }
227
225
  }
228
226
  exports.SaplingTransactionViewer = SaplingTransactionViewer;
229
- _viewingKeyProvider = new WeakMap(), _readProvider = new WeakMap(), _saplingContractId = new WeakMap();
230
- //# sourceMappingURL=sapling-transaction-viewer.js.map
227
+ _SaplingTransactionViewer_viewingKeyProvider = new WeakMap(), _SaplingTransactionViewer_readProvider = new WeakMap(), _SaplingTransactionViewer_saplingContractId = new WeakMap();