@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.
- package/dist/lib/constants.js +0 -1
- package/dist/lib/errors.js +0 -1
- package/dist/lib/sapling-forger/sapling-forger.js +8 -9
- package/dist/lib/sapling-keys/helpers.js +6 -7
- package/dist/lib/sapling-keys/in-memory-proving-key.js +15 -18
- package/dist/lib/sapling-keys/in-memory-spending-key.js +22 -25
- package/dist/lib/sapling-keys/in-memory-viewing-key.js +18 -21
- package/dist/lib/sapling-module-wrapper.js +1 -2
- package/dist/lib/sapling-state/sapling-state.js +6 -7
- package/dist/lib/sapling-state/utils.js +0 -1
- package/dist/lib/sapling-tx-builder/sapling-transactions-builder.js +78 -80
- package/dist/lib/sapling-tx-viewer/helpers.js +2 -3
- package/dist/lib/sapling-tx-viewer/sapling-transaction-viewer.js +36 -39
- package/dist/lib/taquito-sapling.js +55 -58
- package/dist/lib/types.js +0 -1
- package/dist/lib/version.js +2 -3
- package/dist/taquito-sapling.es6.js +1383 -1380
- package/dist/taquito-sapling.es6.js.map +1 -1
- package/dist/taquito-sapling.umd.js +1387 -1393
- package/dist/taquito-sapling.umd.js.map +1 -1
- package/dist/types/constants.d.ts +5 -5
- package/dist/types/errors.d.ts +52 -52
- package/dist/types/sapling-forger/sapling-forger.d.ts +30 -30
- package/dist/types/sapling-keys/helpers.d.ts +2 -2
- package/dist/types/sapling-keys/in-memory-proving-key.d.ts +35 -35
- package/dist/types/sapling-keys/in-memory-spending-key.d.ts +53 -53
- package/dist/types/sapling-keys/in-memory-viewing-key.d.ts +48 -48
- package/dist/types/sapling-module-wrapper.d.ts +19 -19
- package/dist/types/sapling-state/sapling-state.d.ts +56 -56
- package/dist/types/sapling-state/utils.d.ts +22 -22
- package/dist/types/sapling-tx-builder/sapling-transactions-builder.d.ts +32 -32
- package/dist/types/sapling-tx-viewer/helpers.d.ts +11 -11
- package/dist/types/sapling-tx-viewer/sapling-transaction-viewer.d.ts +50 -50
- package/dist/types/taquito-sapling.d.ts +81 -81
- package/dist/types/types.d.ts +147 -147
- package/dist/types/version.d.ts +4 -4
- package/package.json +33 -35
- package/dist/lib/constants.js.map +0 -1
- package/dist/lib/errors.js.map +0 -1
- package/dist/lib/sapling-forger/sapling-forger.js.map +0 -1
- package/dist/lib/sapling-keys/helpers.js.map +0 -1
- package/dist/lib/sapling-keys/in-memory-proving-key.js.map +0 -1
- package/dist/lib/sapling-keys/in-memory-spending-key.js.map +0 -1
- package/dist/lib/sapling-keys/in-memory-viewing-key.js.map +0 -1
- package/dist/lib/sapling-module-wrapper.js.map +0 -1
- package/dist/lib/sapling-state/sapling-state.js.map +0 -1
- package/dist/lib/sapling-state/utils.js.map +0 -1
- package/dist/lib/sapling-tx-builder/sapling-transactions-builder.js.map +0 -1
- package/dist/lib/sapling-tx-viewer/helpers.js.map +0 -1
- package/dist/lib/sapling-tx-viewer/sapling-transaction-viewer.js.map +0 -1
- package/dist/lib/taquito-sapling.js.map +0 -1
- package/dist/lib/types.js.map +0 -1
- 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,
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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,
|
|
19
|
-
if (!
|
|
20
|
-
|
|
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
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
__classPrivateFieldSet(this,
|
|
48
|
-
__classPrivateFieldSet(this,
|
|
49
|
-
__classPrivateFieldSet(this,
|
|
50
|
-
__classPrivateFieldSet(this,
|
|
51
|
-
__classPrivateFieldSet(this,
|
|
52
|
-
__classPrivateFieldSet(this,
|
|
53
|
-
__classPrivateFieldSet(this,
|
|
54
|
-
__classPrivateFieldSet(this,
|
|
55
|
-
__classPrivateFieldSet(this,
|
|
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,
|
|
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,
|
|
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,
|
|
93
|
-
const saplingViewer = yield __classPrivateFieldGet(this,
|
|
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,
|
|
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,
|
|
149
|
-
const { commitmentValue, commitment, proof } = yield __classPrivateFieldGet(this,
|
|
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,
|
|
157
|
-
const ephemeralPublicKey = yield __classPrivateFieldGet(this,
|
|
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,
|
|
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,
|
|
183
|
+
const publicKeyReRandomization = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").randR();
|
|
186
184
|
let stateDiff;
|
|
187
|
-
if (__classPrivateFieldGet(this,
|
|
188
|
-
stateDiff = yield __classPrivateFieldGet(this,
|
|
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,
|
|
189
|
+
stateDiff = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_readProvider, "f").getSaplingDiffByContract(__classPrivateFieldGet(this, _SaplingTransactionBuilder_contractAddress, "f"), 'head');
|
|
192
190
|
}
|
|
193
|
-
const stateTree = yield __classPrivateFieldGet(this,
|
|
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,
|
|
198
|
-
const unsignedSpendDescription = __classPrivateFieldGet(this,
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
234
|
-
const keyAgreement = yield __classPrivateFieldGet(this,
|
|
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,
|
|
237
|
-
const transactionPlaintext = __classPrivateFieldGet(this,
|
|
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,
|
|
240
|
+
memoSize: __classPrivateFieldGet(this, _SaplingTransactionBuilder_memoSize, "f") * 2,
|
|
242
241
|
memo: parametersCiphertext.memo,
|
|
243
242
|
});
|
|
244
|
-
const nonceOut = Buffer.from(__classPrivateFieldGet(this,
|
|
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,
|
|
270
|
-
const inputs = __classPrivateFieldGet(this,
|
|
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,
|
|
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,
|
|
276
|
+
let chainId = __classPrivateFieldGet(this, _SaplingTransactionBuilder_chainId, "f");
|
|
278
277
|
if (!chainId) {
|
|
279
|
-
chainId = yield __classPrivateFieldGet(this,
|
|
280
|
-
__classPrivateFieldSet(this,
|
|
278
|
+
chainId = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_readProvider, "f").getChainId();
|
|
279
|
+
__classPrivateFieldSet(this, _SaplingTransactionBuilder_chainId, chainId, "f");
|
|
281
280
|
}
|
|
282
|
-
return Buffer.from(`${__classPrivateFieldGet(this,
|
|
281
|
+
return Buffer.from(`${__classPrivateFieldGet(this, _SaplingTransactionBuilder_contractAddress, "f")}${chainId}`);
|
|
283
282
|
});
|
|
284
283
|
}
|
|
285
284
|
}
|
|
286
285
|
exports.SaplingTransactionBuilder = SaplingTransactionBuilder;
|
|
287
|
-
|
|
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,
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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,
|
|
19
|
-
if (!
|
|
20
|
-
|
|
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
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
__classPrivateFieldSet(this,
|
|
59
|
-
__classPrivateFieldSet(this,
|
|
60
|
-
__classPrivateFieldSet(this,
|
|
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,
|
|
134
|
-
saplingDiffResponse = yield __classPrivateFieldGet(this,
|
|
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,
|
|
137
|
-
saplingDiffResponse = yield __classPrivateFieldGet(this,
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
-
|
|
230
|
-
//# sourceMappingURL=sapling-transaction-viewer.js.map
|
|
227
|
+
_SaplingTransactionViewer_viewingKeyProvider = new WeakMap(), _SaplingTransactionViewer_readProvider = new WeakMap(), _SaplingTransactionViewer_saplingContractId = new WeakMap();
|