@taquito/sapling 24.2.0 → 24.3.0-beta.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/lib/errors.js +10 -10
- package/dist/lib/sapling-forger/sapling-forger.js +3 -3
- package/dist/lib/sapling-keys/helpers.js +3 -3
- package/dist/lib/sapling-keys/in-memory-proving-key.js +16 -30
- package/dist/lib/sapling-keys/in-memory-spending-key.js +48 -68
- package/dist/lib/sapling-keys/in-memory-viewing-key.js +20 -37
- package/dist/lib/sapling-module-wrapper.js +33 -57
- package/dist/lib/sapling-state/sapling-state.js +83 -106
- package/dist/lib/sapling-state/utils.js +7 -18
- package/dist/lib/sapling-tx-builder/sapling-transactions-builder.js +194 -216
- package/dist/lib/sapling-tx-viewer/sapling-transaction-viewer.js +98 -135
- package/dist/lib/taquito-sapling.js +84 -119
- package/dist/lib/version.js +2 -2
- package/dist/taquito-sapling.es6.js +605 -727
- package/dist/taquito-sapling.es6.js.map +1 -1
- package/dist/taquito-sapling.umd.js +604 -726
- package/dist/taquito-sapling.umd.js.map +1 -1
- package/dist/types/constants.d.ts +1 -1
- package/dist/types/errors.d.ts +11 -8
- package/dist/types/sapling-forger/sapling-forger.d.ts +5 -5
- package/dist/types/sapling-keys/helpers.d.ts +1 -1
- package/dist/types/sapling-keys/in-memory-proving-key.d.ts +3 -4
- package/dist/types/sapling-keys/in-memory-spending-key.d.ts +4 -5
- package/dist/types/sapling-keys/in-memory-viewing-key.d.ts +9 -9
- package/dist/types/sapling-module-wrapper.d.ts +11 -11
- package/dist/types/sapling-state/sapling-state.d.ts +1 -1
- package/dist/types/sapling-state/utils.d.ts +1 -1
- package/dist/types/sapling-tx-builder/sapling-transactions-builder.d.ts +3 -3
- package/dist/types/sapling-tx-viewer/helpers.d.ts +1 -1
- package/dist/types/sapling-tx-viewer/sapling-transaction-viewer.d.ts +4 -4
- package/dist/types/taquito-sapling.d.ts +5 -5
- package/package.json +26 -13
- package/LICENSE +0 -202
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
3
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
4
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
@@ -52,241 +43,228 @@ class SaplingTransactionBuilder {
|
|
|
52
43
|
__classPrivateFieldSet(this, _SaplingTransactionBuilder_saplingWrapper, saplingWrapper, "f");
|
|
53
44
|
__classPrivateFieldSet(this, _SaplingTransactionBuilder_readProvider, readProvider, "f");
|
|
54
45
|
}
|
|
55
|
-
createShieldedTx(saplingTransactionParams, txTotalAmount, boundData) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
outputs.push(yield this.prepareSaplingOutputDescription({
|
|
67
|
-
saplingContext,
|
|
68
|
-
address,
|
|
69
|
-
amount: saplingTransactionParams[i].amount,
|
|
70
|
-
memo: saplingTransactionParams[i].memo,
|
|
71
|
-
randomCommitmentTrapdoor: rcm,
|
|
72
|
-
}));
|
|
73
|
-
}
|
|
74
|
-
const signature = yield this.createBindingSignature({
|
|
46
|
+
async createShieldedTx(saplingTransactionParams, txTotalAmount, boundData) {
|
|
47
|
+
const rcm = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").randR();
|
|
48
|
+
const balance = this.calculateTransactionBalance('0', txTotalAmount.toString());
|
|
49
|
+
const { signature, inputs, outputs } = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").withProvingContext(async (saplingContext) => {
|
|
50
|
+
const outputs = [];
|
|
51
|
+
const inputs = [];
|
|
52
|
+
for (const i in saplingTransactionParams) {
|
|
53
|
+
const [address] = (0, utils_1.b58DecodeAndCheckPrefix)(saplingTransactionParams[i].to, [
|
|
54
|
+
utils_1.PrefixV2.SaplingAddress,
|
|
55
|
+
]);
|
|
56
|
+
outputs.push(await this.prepareSaplingOutputDescription({
|
|
75
57
|
saplingContext,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
58
|
+
address,
|
|
59
|
+
amount: saplingTransactionParams[i].amount,
|
|
60
|
+
memo: saplingTransactionParams[i].memo,
|
|
61
|
+
randomCommitmentTrapdoor: rcm,
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
const signature = await this.createBindingSignature({
|
|
65
|
+
saplingContext,
|
|
84
66
|
inputs,
|
|
85
67
|
outputs,
|
|
86
|
-
signature,
|
|
87
68
|
balance,
|
|
88
|
-
|
|
69
|
+
boundData,
|
|
70
|
+
});
|
|
71
|
+
return { signature, inputs, outputs };
|
|
89
72
|
});
|
|
73
|
+
return {
|
|
74
|
+
inputs,
|
|
75
|
+
outputs,
|
|
76
|
+
signature,
|
|
77
|
+
balance,
|
|
78
|
+
};
|
|
90
79
|
}
|
|
91
|
-
createSaplingTx(saplingTransactionParams, txTotalAmount, boundData, chosenInputs) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
outputs.push(yield this.prepareSaplingOutputDescription({
|
|
107
|
-
saplingContext,
|
|
108
|
-
address,
|
|
109
|
-
amount: saplingTransactionParams[i].amount,
|
|
110
|
-
memo: saplingTransactionParams[i].memo,
|
|
111
|
-
randomCommitmentTrapdoor,
|
|
112
|
-
outgoingViewingKey,
|
|
113
|
-
}));
|
|
114
|
-
}
|
|
115
|
-
if (chosenInputs.sumSelectedInputs.isGreaterThan(sumAmountOutput)) {
|
|
116
|
-
const payBackAddress = (yield saplingViewer.getAddress()).address;
|
|
117
|
-
const [address] = (0, utils_1.b58DecodeAndCheckPrefix)(payBackAddress, [utils_1.PrefixV2.SaplingAddress]);
|
|
118
|
-
const { payBackOutput, payBackAmount } = yield this.createPaybackOutput({
|
|
119
|
-
saplingContext,
|
|
120
|
-
address,
|
|
121
|
-
amount: txTotalAmount.toString(),
|
|
122
|
-
memo: constants_1.DEFAULT_MEMO,
|
|
123
|
-
randomCommitmentTrapdoor: randomCommitmentTrapdoor,
|
|
124
|
-
outgoingViewingKey: outgoingViewingKey,
|
|
125
|
-
}, chosenInputs.sumSelectedInputs);
|
|
126
|
-
sumAmountOutput = sumAmountOutput.plus(new bignumber_js_1.default(payBackAmount));
|
|
127
|
-
outputs.push(payBackOutput);
|
|
128
|
-
}
|
|
129
|
-
const balance = this.calculateTransactionBalance(chosenInputs.sumSelectedInputs.toString(), sumAmountOutput.toString());
|
|
130
|
-
const signature = yield this.createBindingSignature({
|
|
80
|
+
async createSaplingTx(saplingTransactionParams, txTotalAmount, boundData, chosenInputs) {
|
|
81
|
+
const randomCommitmentTrapdoor = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").randR();
|
|
82
|
+
const saplingViewer = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_inMemorySpendingKey, "f").getSaplingViewingKeyProvider();
|
|
83
|
+
const outgoingViewingKey = await saplingViewer.getOutgoingViewingKey();
|
|
84
|
+
const { signature, balance, inputs, outputs } = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").withProvingContext(async (saplingContext) => {
|
|
85
|
+
const outputs = [];
|
|
86
|
+
const inputs = [];
|
|
87
|
+
inputs.push(...(await this.prepareSaplingSpendDescription(saplingContext, chosenInputs.inputsToSpend)));
|
|
88
|
+
let sumAmountOutput = new bignumber_js_1.default(0);
|
|
89
|
+
for (const i in saplingTransactionParams) {
|
|
90
|
+
sumAmountOutput = sumAmountOutput.plus(new bignumber_js_1.default(saplingTransactionParams[i].amount));
|
|
91
|
+
const [address] = (0, utils_1.b58DecodeAndCheckPrefix)(saplingTransactionParams[i].to, [
|
|
92
|
+
utils_1.PrefixV2.SaplingAddress,
|
|
93
|
+
]);
|
|
94
|
+
outputs.push(await this.prepareSaplingOutputDescription({
|
|
131
95
|
saplingContext,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
96
|
+
address,
|
|
97
|
+
amount: saplingTransactionParams[i].amount,
|
|
98
|
+
memo: saplingTransactionParams[i].memo,
|
|
99
|
+
randomCommitmentTrapdoor,
|
|
100
|
+
outgoingViewingKey,
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
if (chosenInputs.sumSelectedInputs.isGreaterThan(sumAmountOutput)) {
|
|
104
|
+
const payBackAddress = (await saplingViewer.getAddress()).address;
|
|
105
|
+
const [address] = (0, utils_1.b58DecodeAndCheckPrefix)(payBackAddress, [utils_1.PrefixV2.SaplingAddress]);
|
|
106
|
+
const { payBackOutput, payBackAmount } = await this.createPaybackOutput({
|
|
107
|
+
saplingContext,
|
|
108
|
+
address,
|
|
109
|
+
amount: txTotalAmount.toString(),
|
|
110
|
+
memo: constants_1.DEFAULT_MEMO,
|
|
111
|
+
randomCommitmentTrapdoor: randomCommitmentTrapdoor,
|
|
112
|
+
outgoingViewingKey: outgoingViewingKey,
|
|
113
|
+
}, chosenInputs.sumSelectedInputs);
|
|
114
|
+
sumAmountOutput = sumAmountOutput.plus(new bignumber_js_1.default(payBackAmount));
|
|
115
|
+
outputs.push(payBackOutput);
|
|
116
|
+
}
|
|
117
|
+
const balance = this.calculateTransactionBalance(chosenInputs.sumSelectedInputs.toString(), sumAmountOutput.toString());
|
|
118
|
+
const signature = await this.createBindingSignature({
|
|
119
|
+
saplingContext,
|
|
140
120
|
inputs,
|
|
141
121
|
outputs,
|
|
142
|
-
signature,
|
|
143
122
|
balance,
|
|
144
|
-
|
|
123
|
+
boundData,
|
|
124
|
+
});
|
|
125
|
+
return { signature, balance, inputs, outputs };
|
|
145
126
|
});
|
|
127
|
+
return {
|
|
128
|
+
inputs,
|
|
129
|
+
outputs,
|
|
130
|
+
signature,
|
|
131
|
+
balance,
|
|
132
|
+
};
|
|
146
133
|
}
|
|
147
134
|
// sum of values of inputs minus sums of values of output equals balance
|
|
148
135
|
calculateTransactionBalance(inputTotal, outputTotal) {
|
|
149
136
|
return new bignumber_js_1.default(inputTotal).minus(new bignumber_js_1.default(outputTotal));
|
|
150
137
|
}
|
|
151
|
-
prepareSaplingOutputDescription(parametersOutputDescription) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
commitmentValue,
|
|
166
|
-
commitment,
|
|
167
|
-
ephemeralPublicKey,
|
|
168
|
-
parametersOutputDescription.outgoingViewingKey,
|
|
169
|
-
]), Buffer.from(constants_1.OCK_KEY), 32)
|
|
170
|
-
: __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").getRandomBytes(32);
|
|
171
|
-
const ciphertext = yield this.encryptCiphertext({
|
|
172
|
-
address: parametersOutputDescription.address,
|
|
173
|
-
ephemeralPrivateKey,
|
|
174
|
-
diversifier,
|
|
175
|
-
outgoingCipherKey,
|
|
176
|
-
amount: parametersOutputDescription.amount,
|
|
177
|
-
randomCommitmentTrapdoor: parametersOutputDescription.randomCommitmentTrapdoor,
|
|
178
|
-
memo: parametersOutputDescription.memo,
|
|
179
|
-
});
|
|
180
|
-
return {
|
|
138
|
+
async prepareSaplingOutputDescription(parametersOutputDescription) {
|
|
139
|
+
const ephemeralPrivateKey = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").randR();
|
|
140
|
+
const { commitmentValue, commitment, proof } = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").preparePartialOutputDescription({
|
|
141
|
+
saplingContext: parametersOutputDescription.saplingContext,
|
|
142
|
+
address: parametersOutputDescription.address,
|
|
143
|
+
randomCommitmentTrapdoor: parametersOutputDescription.randomCommitmentTrapdoor,
|
|
144
|
+
ephemeralPrivateKey,
|
|
145
|
+
amount: parametersOutputDescription.amount,
|
|
146
|
+
});
|
|
147
|
+
const diversifier = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").getDiversifiedFromRawPaymentAddress(parametersOutputDescription.address);
|
|
148
|
+
const ephemeralPublicKey = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").deriveEphemeralPublicKey(diversifier, ephemeralPrivateKey);
|
|
149
|
+
const outgoingCipherKey = parametersOutputDescription.outgoingViewingKey
|
|
150
|
+
? blakejs_1.default.blake2b(Buffer.concat([
|
|
151
|
+
commitmentValue,
|
|
181
152
|
commitment,
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
153
|
+
ephemeralPublicKey,
|
|
154
|
+
parametersOutputDescription.outgoingViewingKey,
|
|
155
|
+
]), Buffer.from(constants_1.OCK_KEY), 32)
|
|
156
|
+
: __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").getRandomBytes(32);
|
|
157
|
+
const ciphertext = await this.encryptCiphertext({
|
|
158
|
+
address: parametersOutputDescription.address,
|
|
159
|
+
ephemeralPrivateKey,
|
|
160
|
+
diversifier,
|
|
161
|
+
outgoingCipherKey,
|
|
162
|
+
amount: parametersOutputDescription.amount,
|
|
163
|
+
randomCommitmentTrapdoor: parametersOutputDescription.randomCommitmentTrapdoor,
|
|
164
|
+
memo: parametersOutputDescription.memo,
|
|
186
165
|
});
|
|
166
|
+
return {
|
|
167
|
+
commitment,
|
|
168
|
+
proof,
|
|
169
|
+
ciphertext: {
|
|
170
|
+
...ciphertext,
|
|
171
|
+
commitmentValue,
|
|
172
|
+
ephemeralPublicKey,
|
|
173
|
+
},
|
|
174
|
+
};
|
|
187
175
|
}
|
|
188
|
-
prepareSaplingSpendDescription(saplingContext, inputsToSpend) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
randomCommitmentTrapdoor: inputsToSpend[i].randomCommitmentTrapdoor,
|
|
208
|
-
publicKeyReRandomization,
|
|
209
|
-
amount,
|
|
210
|
-
root: stateDiff.root,
|
|
211
|
-
witness,
|
|
212
|
-
})
|
|
213
|
-
: yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_inMemorySpendingKey, "f").prepareSpendDescription({
|
|
214
|
-
saplingContext,
|
|
215
|
-
address: inputsToSpend[i].paymentAddress,
|
|
216
|
-
randomCommitmentTrapdoor: inputsToSpend[i].randomCommitmentTrapdoor,
|
|
217
|
-
publicKeyReRandomization,
|
|
218
|
-
amount,
|
|
219
|
-
root: stateDiff.root,
|
|
220
|
-
witness,
|
|
221
|
-
});
|
|
222
|
-
const unsignedSpendDescriptionBytes = __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingForger, "f").forgeUnsignedTxInput(unsignedSpendDescription);
|
|
223
|
-
const hash = blakejs_1.default.blake2b(unsignedSpendDescriptionBytes, yield this.getAntiReplay(), 32);
|
|
224
|
-
const spendDescription = yield __classPrivateFieldGet(this, _SaplingTransactionBuilder_inMemorySpendingKey, "f").signSpendDescription({
|
|
176
|
+
async prepareSaplingSpendDescription(saplingContext, inputsToSpend) {
|
|
177
|
+
const publicKeyReRandomization = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").randR();
|
|
178
|
+
let stateDiff;
|
|
179
|
+
if (__classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingId, "f")) {
|
|
180
|
+
stateDiff = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_readProvider, "f").getSaplingDiffById({ id: __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingId, "f") }, 'head');
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
stateDiff = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_readProvider, "f").getSaplingDiffByContract(__classPrivateFieldGet(this, _SaplingTransactionBuilder_contractAddress, "f"), 'head');
|
|
184
|
+
}
|
|
185
|
+
const stateTree = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingState, "f").getStateTree(stateDiff, true);
|
|
186
|
+
const saplingSpendDescriptions = [];
|
|
187
|
+
for (let i = 0; i < inputsToSpend.length; i++) {
|
|
188
|
+
const amount = (0, helpers_1.convertValueToBigNumber)(inputsToSpend[i].value).toString();
|
|
189
|
+
const witness = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingState, "f").getWitness(stateTree, new bignumber_js_1.default(inputsToSpend[i].position));
|
|
190
|
+
const unsignedSpendDescription = __classPrivateFieldGet(this, _SaplingTransactionBuilder_inMemoryProvingKey, "f")
|
|
191
|
+
? await __classPrivateFieldGet(this, _SaplingTransactionBuilder_inMemoryProvingKey, "f").prepareSpendDescription({
|
|
192
|
+
saplingContext,
|
|
193
|
+
address: inputsToSpend[i].paymentAddress,
|
|
194
|
+
randomCommitmentTrapdoor: inputsToSpend[i].randomCommitmentTrapdoor,
|
|
225
195
|
publicKeyReRandomization,
|
|
226
|
-
|
|
227
|
-
|
|
196
|
+
amount,
|
|
197
|
+
root: stateDiff.root,
|
|
198
|
+
witness,
|
|
199
|
+
})
|
|
200
|
+
: await __classPrivateFieldGet(this, _SaplingTransactionBuilder_inMemorySpendingKey, "f").prepareSpendDescription({
|
|
201
|
+
saplingContext,
|
|
202
|
+
address: inputsToSpend[i].paymentAddress,
|
|
203
|
+
randomCommitmentTrapdoor: inputsToSpend[i].randomCommitmentTrapdoor,
|
|
204
|
+
publicKeyReRandomization,
|
|
205
|
+
amount,
|
|
206
|
+
root: stateDiff.root,
|
|
207
|
+
witness,
|
|
228
208
|
});
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
209
|
+
const unsignedSpendDescriptionBytes = __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingForger, "f").forgeUnsignedTxInput(unsignedSpendDescription);
|
|
210
|
+
const hash = blakejs_1.default.blake2b(unsignedSpendDescriptionBytes, await this.getAntiReplay(), 32);
|
|
211
|
+
const spendDescription = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_inMemorySpendingKey, "f").signSpendDescription({
|
|
212
|
+
publicKeyReRandomization,
|
|
213
|
+
unsignedSpendDescription,
|
|
214
|
+
hash,
|
|
215
|
+
});
|
|
216
|
+
if (spendDescription.signature === undefined) {
|
|
217
|
+
throw new Error('Spend signing failed');
|
|
233
218
|
}
|
|
234
|
-
|
|
235
|
-
}
|
|
219
|
+
saplingSpendDescriptions.push(spendDescription);
|
|
220
|
+
}
|
|
221
|
+
return saplingSpendDescriptions;
|
|
236
222
|
}
|
|
237
|
-
encryptCiphertext(parametersCiphertext) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
memo: parametersCiphertext.memo,
|
|
249
|
-
});
|
|
250
|
-
const nonceOut = Buffer.from(__classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").getRandomBytes(24));
|
|
251
|
-
const payloadEnc = Buffer.from((0, nacl_1.secretBox)(keyAgreementHash, nonceEnc, transactionPlaintext));
|
|
252
|
-
const payloadOut = Buffer.from((0, nacl_1.secretBox)(parametersCiphertext.outgoingCipherKey, nonceOut, Buffer.concat([
|
|
253
|
-
recipientDiversifiedTransmissionKey,
|
|
254
|
-
parametersCiphertext.ephemeralPrivateKey,
|
|
255
|
-
])));
|
|
256
|
-
return { payloadEnc, nonceEnc, payloadOut, nonceOut };
|
|
223
|
+
async encryptCiphertext(parametersCiphertext) {
|
|
224
|
+
const recipientDiversifiedTransmissionKey = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").getPkdFromRawPaymentAddress(parametersCiphertext.address);
|
|
225
|
+
const keyAgreement = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").keyAgreement(recipientDiversifiedTransmissionKey, parametersCiphertext.ephemeralPrivateKey);
|
|
226
|
+
const keyAgreementHash = blakejs_1.default.blake2b(keyAgreement, Buffer.from(constants_1.KDF_KEY), 32);
|
|
227
|
+
const nonceEnc = Buffer.from(__classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").getRandomBytes(24));
|
|
228
|
+
const transactionPlaintext = __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingForger, "f").forgeTransactionPlaintext({
|
|
229
|
+
diversifier: parametersCiphertext.diversifier,
|
|
230
|
+
amount: parametersCiphertext.amount,
|
|
231
|
+
randomCommitmentTrapdoor: parametersCiphertext.randomCommitmentTrapdoor,
|
|
232
|
+
memoSize: __classPrivateFieldGet(this, _SaplingTransactionBuilder_memoSize, "f") * 2,
|
|
233
|
+
memo: parametersCiphertext.memo,
|
|
257
234
|
});
|
|
235
|
+
const nonceOut = Buffer.from(__classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").getRandomBytes(24));
|
|
236
|
+
const payloadEnc = Buffer.from((0, nacl_1.secretBox)(keyAgreementHash, nonceEnc, transactionPlaintext));
|
|
237
|
+
const payloadOut = Buffer.from((0, nacl_1.secretBox)(parametersCiphertext.outgoingCipherKey, nonceOut, Buffer.concat([
|
|
238
|
+
recipientDiversifiedTransmissionKey,
|
|
239
|
+
parametersCiphertext.ephemeralPrivateKey,
|
|
240
|
+
])));
|
|
241
|
+
return { payloadEnc, nonceEnc, payloadOut, nonceOut };
|
|
258
242
|
}
|
|
259
|
-
createPaybackOutput(params, sumSelectedInputs) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
outgoingViewingKey: params.outgoingViewingKey,
|
|
269
|
-
});
|
|
270
|
-
return { payBackOutput, payBackAmount };
|
|
243
|
+
async createPaybackOutput(params, sumSelectedInputs) {
|
|
244
|
+
const payBackAmount = sumSelectedInputs.minus(params.amount).toString();
|
|
245
|
+
const payBackOutput = await this.prepareSaplingOutputDescription({
|
|
246
|
+
saplingContext: params.saplingContext,
|
|
247
|
+
address: params.address,
|
|
248
|
+
amount: payBackAmount,
|
|
249
|
+
memo: params.memo,
|
|
250
|
+
randomCommitmentTrapdoor: params.randomCommitmentTrapdoor,
|
|
251
|
+
outgoingViewingKey: params.outgoingViewingKey,
|
|
271
252
|
});
|
|
253
|
+
return { payBackOutput, payBackAmount };
|
|
272
254
|
}
|
|
273
|
-
createBindingSignature(parametersBindingSig) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
return __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").createBindingSignature(parametersBindingSig.saplingContext, parametersBindingSig.balance.toFixed(), transactionSigHash);
|
|
279
|
-
});
|
|
255
|
+
async createBindingSignature(parametersBindingSig) {
|
|
256
|
+
const outputs = __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingForger, "f").forgeOutputDescriptions(parametersBindingSig.outputs);
|
|
257
|
+
const inputs = __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingForger, "f").forgeSpendDescriptions(parametersBindingSig.inputs);
|
|
258
|
+
const transactionSigHash = blakejs_1.default.blake2b(Buffer.concat([inputs, outputs, parametersBindingSig.boundData]), await this.getAntiReplay(), 32);
|
|
259
|
+
return __classPrivateFieldGet(this, _SaplingTransactionBuilder_saplingWrapper, "f").createBindingSignature(parametersBindingSig.saplingContext, parametersBindingSig.balance.toFixed(), transactionSigHash);
|
|
280
260
|
}
|
|
281
|
-
getAntiReplay() {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
return Buffer.from(`${__classPrivateFieldGet(this, _SaplingTransactionBuilder_contractAddress, "f")}${chainId}`);
|
|
289
|
-
});
|
|
261
|
+
async getAntiReplay() {
|
|
262
|
+
let chainId = __classPrivateFieldGet(this, _SaplingTransactionBuilder_chainId, "f");
|
|
263
|
+
if (!chainId) {
|
|
264
|
+
chainId = await __classPrivateFieldGet(this, _SaplingTransactionBuilder_readProvider, "f").getChainId();
|
|
265
|
+
__classPrivateFieldSet(this, _SaplingTransactionBuilder_chainId, chainId, "f");
|
|
266
|
+
}
|
|
267
|
+
return Buffer.from(`${__classPrivateFieldGet(this, _SaplingTransactionBuilder_contractAddress, "f")}${chainId}`);
|
|
290
268
|
}
|
|
291
269
|
}
|
|
292
270
|
exports.SaplingTransactionBuilder = SaplingTransactionBuilder;
|