@taquito/sapling 14.0.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/LICENSE +7 -0
- package/README.md +93 -0
- package/dist/lib/constants.js +8 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/error.js +72 -0
- package/dist/lib/error.js.map +1 -0
- package/dist/lib/sapling-forger/sapling-forger.js +101 -0
- package/dist/lib/sapling-forger/sapling-forger.js.map +1 -0
- package/dist/lib/sapling-keys/helpers.js +30 -0
- package/dist/lib/sapling-keys/helpers.js.map +1 -0
- package/dist/lib/sapling-keys/in-memory-proving-key.js +84 -0
- package/dist/lib/sapling-keys/in-memory-proving-key.js.map +1 -0
- package/dist/lib/sapling-keys/in-memory-spending-key.js +146 -0
- package/dist/lib/sapling-keys/in-memory-spending-key.js.map +1 -0
- package/dist/lib/sapling-keys/in-memory-viewing-key.js +101 -0
- package/dist/lib/sapling-keys/in-memory-viewing-key.js.map +1 -0
- package/dist/lib/sapling-module-wrapper.js +83 -0
- package/dist/lib/sapling-module-wrapper.js.map +1 -0
- package/dist/lib/sapling-state/sapling-state.js +171 -0
- package/dist/lib/sapling-state/sapling-state.js.map +1 -0
- package/dist/lib/sapling-state/utils.js +60 -0
- package/dist/lib/sapling-state/utils.js.map +1 -0
- package/dist/lib/sapling-tx-builder/sapling-transactions-builder.js +288 -0
- package/dist/lib/sapling-tx-builder/sapling-transactions-builder.js.map +1 -0
- package/dist/lib/sapling-tx-viewer/helpers.js +31 -0
- package/dist/lib/sapling-tx-viewer/helpers.js.map +1 -0
- package/dist/lib/sapling-tx-viewer/sapling-transaction-viewer.js +230 -0
- package/dist/lib/sapling-tx-viewer/sapling-transaction-viewer.js.map +1 -0
- package/dist/lib/taquito-sapling.js +293 -0
- package/dist/lib/taquito-sapling.js.map +1 -0
- package/dist/lib/types.js +3 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/version.js +9 -0
- package/dist/lib/version.js.map +1 -0
- package/dist/taquito-sapling.es6.js +1456 -0
- package/dist/taquito-sapling.es6.js.map +1 -0
- package/dist/taquito-sapling.umd.js +1485 -0
- package/dist/taquito-sapling.umd.js.map +1 -0
- package/dist/types/constants.d.ts +5 -0
- package/dist/types/error.d.ts +50 -0
- package/dist/types/sapling-forger/sapling-forger.d.ts +30 -0
- package/dist/types/sapling-keys/helpers.d.ts +2 -0
- package/dist/types/sapling-keys/in-memory-proving-key.d.ts +35 -0
- package/dist/types/sapling-keys/in-memory-spending-key.d.ts +53 -0
- package/dist/types/sapling-keys/in-memory-viewing-key.d.ts +48 -0
- package/dist/types/sapling-module-wrapper.d.ts +19 -0
- package/dist/types/sapling-state/sapling-state.d.ts +55 -0
- package/dist/types/sapling-state/utils.d.ts +22 -0
- package/dist/types/sapling-tx-builder/sapling-transactions-builder.d.ts +32 -0
- package/dist/types/sapling-tx-viewer/helpers.d.ts +11 -0
- package/dist/types/sapling-tx-viewer/sapling-transaction-viewer.d.ts +50 -0
- package/dist/types/taquito-sapling.d.ts +81 -0
- package/dist/types/types.d.ts +147 -0
- package/dist/types/version.d.ts +4 -0
- package/fetch-sapling-params.js +41 -0
- package/package.json +112 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2019 ECAD Labs Inc
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Taquito Sapling package
|
|
2
|
+
|
|
3
|
+
_Documentation can be found [here](https://tezostaquito.io/docs/next/sapling)_
|
|
4
|
+
_TypeDoc style documentation is available on-line [here](https://tezostaquito.io/typedoc/modules/_taquito_sapling.html)_
|
|
5
|
+
|
|
6
|
+
## General Information
|
|
7
|
+
|
|
8
|
+
Sapling is a protocol allowing to perform private transactions in a decentralized environment. This package allows to read from a sapling state (retrieve the balance and transaction history) and prepare sapling transactions.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
Install the package as follows
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
npm install @taquito/sapling
|
|
16
|
+
```
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
**Retrieve a balance in the Sapling shielded pool**
|
|
20
|
+
|
|
21
|
+
The returned balance is in mutez.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { TezosToolkit, RpcReadAdapter } from '@taquito/taquito';
|
|
25
|
+
import { SaplingToolkit, InMemorySpendingKey } from '@taquito/sapling';
|
|
26
|
+
|
|
27
|
+
const tezos = new TezosToolkit('https://jakartanet.ecadinfra.com/');
|
|
28
|
+
|
|
29
|
+
const saplingContract = await tezos.contract.at('KT1UYwMR6Q6LZnwQEi77DSBrAjKT1tEJb245');
|
|
30
|
+
|
|
31
|
+
const inMemorySpendingKey = await InMemorySpendingKey.fromMnemonic('YOUR_MNEMONIC');
|
|
32
|
+
|
|
33
|
+
const readProvider = new RpcReadAdapter(tezos.rpc);
|
|
34
|
+
|
|
35
|
+
const saplingToolkit = new SaplingToolkit(
|
|
36
|
+
{ saplingSigner: inMemorySpendingKey },
|
|
37
|
+
{ contractAddress: saplingContract.address, memoSize: 8 },
|
|
38
|
+
readProvider
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
const txViewer = await saplingToolkit.getSaplingTransactionViewer();
|
|
42
|
+
const initialBalance = await txViewer.getBalance();
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Prepare a shielded transaction**
|
|
46
|
+
|
|
47
|
+
A shielded transaction allows sending tokens from a Tezos account (tz1, tz2, tz3) to a Sapling address (zet).
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { TezosToolkit, RpcReadAdapter } from '@taquito/taquito';
|
|
51
|
+
import { SaplingToolkit, InMemorySpendingKey } from '@taquito/sapling';
|
|
52
|
+
|
|
53
|
+
const tezos = new TezosToolkit('https://jakartanet.ecadinfra.com/');
|
|
54
|
+
// set up your signer on the TezosToolkit as usual
|
|
55
|
+
const saplingContract = await tezos.contract.at('KT1UYwMR6Q6LZnwQEi77DSBrAjKT1tEJb245');
|
|
56
|
+
|
|
57
|
+
const inMemorySpendingKey = await InMemorySpendingKey.fromMnemonic('YOUR_MNEMONIC');
|
|
58
|
+
|
|
59
|
+
const readProvider = new RpcReadAdapter(tezos.rpc);
|
|
60
|
+
|
|
61
|
+
const saplingToolkit = new SaplingToolkit(
|
|
62
|
+
{ saplingSigner: inMemorySpendingKey },
|
|
63
|
+
{ contractAddress: saplingContract.address, memoSize: 8 },
|
|
64
|
+
readProvider
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
// Fetch a payment address (zet)
|
|
68
|
+
const inMemoryViewingKey = await inMemorySpendingKey.getSaplingViewingKeyProvider();
|
|
69
|
+
const paymentAddress = (await inMemoryViewingKey.getAddress()).address;
|
|
70
|
+
|
|
71
|
+
// prepare the shielded transaction
|
|
72
|
+
const shieldedTx = await saplingToolkit.prepareShieldedTransaction([{
|
|
73
|
+
to: paymentAddress,
|
|
74
|
+
amount: 3,
|
|
75
|
+
memo: 'test',
|
|
76
|
+
mutez: false // set to false by default
|
|
77
|
+
}])
|
|
78
|
+
|
|
79
|
+
// Inject the sapling transaction using the ContractAbstraction
|
|
80
|
+
// The amount MUST be specified in the send method to transfer the 3 tez to the shielded pool
|
|
81
|
+
const op = await saplingContract.methods.default([shieldedTx]).send({ amount: 3 });
|
|
82
|
+
await op.confirmation();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Refer to the website documentation for further examples and information: https://tezostaquito.io/docs/next/sapling
|
|
86
|
+
|
|
87
|
+
## Additional info
|
|
88
|
+
|
|
89
|
+
See the top-level project [https://github.com/ecadlabs/taquito](https://github.com/ecadlabs/taquito) for details on reporting issues, contributing and versioning.
|
|
90
|
+
|
|
91
|
+
## Disclaimer
|
|
92
|
+
|
|
93
|
+
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_BOUND_DATA = exports.DEFAULT_MEMO = exports.OCK_KEY = exports.KDF_KEY = void 0;
|
|
4
|
+
exports.KDF_KEY = 'KDFSaplingForTezosV1';
|
|
5
|
+
exports.OCK_KEY = 'OCK_keystringderivation_TEZOS';
|
|
6
|
+
exports.DEFAULT_MEMO = '';
|
|
7
|
+
exports.DEFAULT_BOUND_DATA = Buffer.from('', 'hex');
|
|
8
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,sBAAsB,CAAC;AACjC,QAAA,OAAO,GAAG,+BAA+B,CAAC;AAC1C,QAAA,YAAY,GAAG,EAAE,CAAC;AAClB,QAAA,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InvalidParameter = exports.InsufficientBalance = exports.InvalidMemo = exports.TreeConstructionFailure = exports.InvalidMerkleRootError = exports.InvalidSpendingKey = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @category Error
|
|
6
|
+
* @description Error indicating that the spending key is invalid
|
|
7
|
+
*/
|
|
8
|
+
class InvalidSpendingKey extends Error {
|
|
9
|
+
constructor(sk, reason = 'The spending key is invalid') {
|
|
10
|
+
super(`${reason}: ${sk}`);
|
|
11
|
+
this.name = 'InvalidSpendingKey';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.InvalidSpendingKey = InvalidSpendingKey;
|
|
15
|
+
/**
|
|
16
|
+
* @category Error
|
|
17
|
+
* @description Error that indicates an invalid Merkle root being passed
|
|
18
|
+
*/
|
|
19
|
+
class InvalidMerkleRootError extends Error {
|
|
20
|
+
constructor(root) {
|
|
21
|
+
super(`The following Merkle tree is invalid: ${JSON.stringify(root)}`);
|
|
22
|
+
this.root = root;
|
|
23
|
+
this.name = 'InvalidMerkleRootError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.InvalidMerkleRootError = InvalidMerkleRootError;
|
|
27
|
+
/**
|
|
28
|
+
* @category Error
|
|
29
|
+
* @description Error that indicates a failure when trying to construct the Merkle tree
|
|
30
|
+
*/
|
|
31
|
+
class TreeConstructionFailure extends Error {
|
|
32
|
+
constructor(message) {
|
|
33
|
+
super(message);
|
|
34
|
+
this.message = message;
|
|
35
|
+
this.name = 'TreeConstructionFailure';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.TreeConstructionFailure = TreeConstructionFailure;
|
|
39
|
+
/**
|
|
40
|
+
* @category Error
|
|
41
|
+
* @description Error indicating that the memo is invalid
|
|
42
|
+
*/
|
|
43
|
+
class InvalidMemo extends Error {
|
|
44
|
+
constructor(memo, errorDetail) {
|
|
45
|
+
super(`The memo '${memo}' is invalid. ${errorDetail}`);
|
|
46
|
+
this.name = 'InvalidMemo';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.InvalidMemo = InvalidMemo;
|
|
50
|
+
/**
|
|
51
|
+
* @category Error
|
|
52
|
+
* @description Error indicating that there is not enough balance to prepare the sapling transaction
|
|
53
|
+
*/
|
|
54
|
+
class InsufficientBalance extends Error {
|
|
55
|
+
constructor(realBalance, amountToSpend) {
|
|
56
|
+
super(`Unable to spend ${amountToSpend} mutez while the balance is only ${realBalance} mutez.`);
|
|
57
|
+
this.name = 'InsufficientBalance';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.InsufficientBalance = InsufficientBalance;
|
|
61
|
+
/**
|
|
62
|
+
* @category Error
|
|
63
|
+
* @description Error indicating that a parameter is invalid
|
|
64
|
+
*/
|
|
65
|
+
class InvalidParameter extends Error {
|
|
66
|
+
constructor(message) {
|
|
67
|
+
super(message);
|
|
68
|
+
this.name = 'InvalidParameter';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.InvalidParameter = InvalidParameter;
|
|
72
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,MAAa,kBAAmB,SAAQ,KAAK;IAE3C,YAAY,EAAU,EAAE,MAAM,GAAG,6BAA6B;QAC5D,KAAK,CAAC,GAAG,MAAM,KAAK,EAAE,EAAE,CAAC,CAAC;QAFrB,SAAI,GAAG,oBAAoB,CAAC;IAGnC,CAAC;CACF;AALD,gDAKC;AAED;;;GAGG;AACH,MAAa,sBAAuB,SAAQ,KAAK;IAE/C,YAAmB,IAAY;QAC7B,KAAK,CAAC,yCAAyC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QADtD,SAAI,GAAJ,IAAI,CAAQ;QADxB,SAAI,GAAG,wBAAwB,CAAC;IAGvC,CAAC;CACF;AALD,wDAKC;AAED;;;GAGG;AACH,MAAa,uBAAwB,SAAQ,KAAK;IAEhD,YAAmB,OAAe;QAChC,KAAK,CAAC,OAAO,CAAC,CAAC;QADE,YAAO,GAAP,OAAO,CAAQ;QAD3B,SAAI,GAAG,yBAAyB,CAAC;IAGxC,CAAC;CACF;AALD,0DAKC;AAED;;;GAGG;AACH,MAAa,WAAY,SAAQ,KAAK;IAEpC,YAAY,IAAY,EAAE,WAAmB;QAC3C,KAAK,CAAC,aAAa,IAAI,iBAAiB,WAAW,EAAE,CAAC,CAAC;QAFlD,SAAI,GAAG,aAAa,CAAC;IAG5B,CAAC;CACF;AALD,kCAKC;AAED;;;GAGG;AACH,MAAa,mBAAoB,SAAQ,KAAK;IAE5C,YAAY,WAAmB,EAAE,aAAqB;QACpD,KAAK,CAAC,mBAAmB,aAAa,oCAAoC,WAAW,SAAS,CAAC,CAAC;QAF3F,SAAI,GAAG,qBAAqB,CAAC;IAGpC,CAAC;CACF;AALD,kDAKC;AAED;;;GAGG;AACH,MAAa,gBAAiB,SAAQ,KAAK;IAEzC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QAFV,SAAI,GAAG,kBAAkB,CAAC;IAGjC,CAAC;CACF;AALD,4CAKC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SaplingForger = void 0;
|
|
4
|
+
const utils_1 = require("@taquito/utils");
|
|
5
|
+
const bignumber_js_1 = require("bignumber.js");
|
|
6
|
+
class SaplingForger {
|
|
7
|
+
/**
|
|
8
|
+
* @description Forge sapling transactions
|
|
9
|
+
* @param spendDescriptions the list of spend descriptions
|
|
10
|
+
* @param outputDescriptions the list of output descriptions
|
|
11
|
+
* @param signature signature hash
|
|
12
|
+
* @param balance balance of the Sapling contract (input/output difference)
|
|
13
|
+
* @param root root of the merkle tree
|
|
14
|
+
* @returns Forged sapling transaction of type Buffer
|
|
15
|
+
*/
|
|
16
|
+
forgeSaplingTransaction(tx) {
|
|
17
|
+
const spendBuf = this.forgeSpendDescriptions(tx.inputs);
|
|
18
|
+
const spend = Buffer.concat([utils_1.toHexBuf(spendBuf.length, 32), spendBuf]);
|
|
19
|
+
const outputBuf = this.forgeOutputDescriptions(tx.outputs);
|
|
20
|
+
const output = Buffer.concat([utils_1.toHexBuf(outputBuf.length, 32), outputBuf]);
|
|
21
|
+
const root = Buffer.from(tx.root, 'hex');
|
|
22
|
+
return Buffer.concat([
|
|
23
|
+
spend,
|
|
24
|
+
output,
|
|
25
|
+
tx.signature,
|
|
26
|
+
utils_1.toHexBuf(tx.balance, 64),
|
|
27
|
+
root,
|
|
28
|
+
utils_1.toHexBuf(tx.boundData.length, 32),
|
|
29
|
+
tx.boundData,
|
|
30
|
+
]);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @description Forge list of spend descriptions
|
|
34
|
+
* @param spendDescriptions list of spend descriptions
|
|
35
|
+
* @returns concatenated forged bytes of type Buffer
|
|
36
|
+
*/
|
|
37
|
+
forgeSpendDescriptions(spendDescriptions) {
|
|
38
|
+
const descriptions = [];
|
|
39
|
+
for (const i of spendDescriptions) {
|
|
40
|
+
const buff = this.forgeSpendDescription(i);
|
|
41
|
+
descriptions.push(buff);
|
|
42
|
+
}
|
|
43
|
+
return Buffer.concat(descriptions);
|
|
44
|
+
}
|
|
45
|
+
forgeSpendDescription(desc) {
|
|
46
|
+
return Buffer.concat([
|
|
47
|
+
desc.commitmentValue,
|
|
48
|
+
desc.nullifier,
|
|
49
|
+
desc.publicKeyReRandomization,
|
|
50
|
+
desc.proof,
|
|
51
|
+
desc.signature,
|
|
52
|
+
]);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @description Forge list of output descriptions
|
|
56
|
+
* @param outputDescriptions list of output descriptions
|
|
57
|
+
* @returns concatenated forged bytes of type Buffer
|
|
58
|
+
*/
|
|
59
|
+
forgeOutputDescriptions(outputDescriptions) {
|
|
60
|
+
const descriptions = [];
|
|
61
|
+
for (const i of outputDescriptions) {
|
|
62
|
+
const buff = this.forgeOutputDescription(i);
|
|
63
|
+
descriptions.push(buff);
|
|
64
|
+
}
|
|
65
|
+
return Buffer.concat(descriptions);
|
|
66
|
+
}
|
|
67
|
+
forgeOutputDescription(desc) {
|
|
68
|
+
const ct = desc.ciphertext;
|
|
69
|
+
return Buffer.concat([
|
|
70
|
+
desc.commitment,
|
|
71
|
+
desc.proof,
|
|
72
|
+
ct.commitmentValue,
|
|
73
|
+
ct.ephemeralPublicKey,
|
|
74
|
+
utils_1.toHexBuf(ct.payloadEnc.length, 32),
|
|
75
|
+
ct.payloadEnc,
|
|
76
|
+
ct.nonceEnc,
|
|
77
|
+
ct.payloadOut,
|
|
78
|
+
ct.nonceOut,
|
|
79
|
+
]);
|
|
80
|
+
}
|
|
81
|
+
forgeUnsignedTxInput(unsignedSpendDescription) {
|
|
82
|
+
return Buffer.concat([
|
|
83
|
+
unsignedSpendDescription.commitmentValue,
|
|
84
|
+
unsignedSpendDescription.nullifier,
|
|
85
|
+
unsignedSpendDescription.publicKeyReRandomization,
|
|
86
|
+
unsignedSpendDescription.proof,
|
|
87
|
+
]);
|
|
88
|
+
}
|
|
89
|
+
forgeTransactionPlaintext(txPlainText) {
|
|
90
|
+
const encodedMemo = Buffer.from(utils_1.char2Bytes(txPlainText.memo).padEnd(txPlainText.memoSize, '0'), 'hex');
|
|
91
|
+
return Buffer.concat([
|
|
92
|
+
txPlainText.diversifier,
|
|
93
|
+
utils_1.toHexBuf(new bignumber_js_1.default(txPlainText.amount), 64),
|
|
94
|
+
txPlainText.randomCommitmentTrapdoor,
|
|
95
|
+
utils_1.toHexBuf(txPlainText.memoSize, 32),
|
|
96
|
+
encodedMemo,
|
|
97
|
+
]);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.SaplingForger = SaplingForger;
|
|
101
|
+
//# sourceMappingURL=sapling-forger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sapling-forger.js","sourceRoot":"","sources":["../../../src/sapling-forger/sapling-forger.ts"],"names":[],"mappings":";;;AAMA,0CAAsD;AACtD,+CAAqC;AAErC,MAAa,aAAa;IACxB;;;;;;;;OAQG;IACH,uBAAuB,CAAC,EAAsB;QAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,sBAAsB,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;QACxD,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,gBAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;QAEvE,MAAM,SAAS,GAAG,IAAI,CAAC,uBAAuB,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;QAC3D,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,gBAAQ,CAAC,SAAS,CAAC,M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const error_1 = require("../error");
|
|
5
|
+
const typedarray_to_buffer_1 = require("typedarray-to-buffer");
|
|
6
|
+
const nacl_1 = require("@stablelib/nacl");
|
|
7
|
+
const pbkdf2_1 = require("pbkdf2");
|
|
8
|
+
const utils_1 = require("@taquito/utils");
|
|
9
|
+
function decryptKey(spendingKey, password) {
|
|
10
|
+
const keyArr = utils_1.b58cdecode(spendingKey, utils_1.prefix[utils_1.Prefix.SASK]);
|
|
11
|
+
// exit first if no password and key is encrypted
|
|
12
|
+
if (!password && spendingKey.slice(0, 4) !== 'sask') {
|
|
13
|
+
throw new error_1.InvalidSpendingKey(spendingKey, 'no password Provided to decrypt');
|
|
14
|
+
}
|
|
15
|
+
if (password && spendingKey.slice(0, 4) !== 'sask') {
|
|
16
|
+
const salt = typedarray_to_buffer_1.default(keyArr.slice(0, 8));
|
|
17
|
+
const encryptedSk = typedarray_to_buffer_1.default(keyArr.slice(8));
|
|
18
|
+
const encryptionKey = pbkdf2_1.default.pbkdf2Sync(password, salt, 32768, 32, 'sha512');
|
|
19
|
+
const decrypted = nacl_1.openSecretBox(new Uint8Array(encryptionKey), new Uint8Array(24), new Uint8Array(encryptedSk));
|
|
20
|
+
if (!decrypted) {
|
|
21
|
+
throw new error_1.InvalidSpendingKey(spendingKey, 'Encrypted Spending Key or Password Incorrect');
|
|
22
|
+
}
|
|
23
|
+
return typedarray_to_buffer_1.default(decrypted);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return typedarray_to_buffer_1.default(keyArr);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.decryptKey = decryptKey;
|
|
30
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/sapling-keys/helpers.ts"],"names":[],"mappings":";;;AAAA,oCAA8C;AAC9C,+DAA4C;AAC5C,0CAAgD;AAChD,mCAA4B;AAC5B,0CAA4D;AAE5D,SAAgB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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
|
+
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;
|
|
17
|
+
};
|
|
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);
|
|
23
|
+
};
|
|
24
|
+
var _provingKey;
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.InMemoryProvingKey = void 0;
|
|
27
|
+
const sapling = require("@airgap/sapling-wasm");
|
|
28
|
+
const helpers_1 = require("./helpers");
|
|
29
|
+
/**
|
|
30
|
+
* @description holds the proving key, create proof for spend descriptions
|
|
31
|
+
* The class can be instantiated from a proving key or a spending key
|
|
32
|
+
*/
|
|
33
|
+
class InMemoryProvingKey {
|
|
34
|
+
constructor(provingKey) {
|
|
35
|
+
_provingKey.set(this, void 0);
|
|
36
|
+
__classPrivateFieldSet(this, _provingKey, Buffer.from(provingKey, 'hex'));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @description Allows to instantiate the InMemoryProvingKey from an encrypted/unencrypted spending key
|
|
40
|
+
*
|
|
41
|
+
* @param spendingKey Base58Check-encoded spending key
|
|
42
|
+
* @param password Optional password to decrypt the spending key
|
|
43
|
+
* @example
|
|
44
|
+
* ```
|
|
45
|
+
* await InMemoryProvingKey.fromSpendingKey('sask27SLmU9herddHz4qFJBLMjWYMbJF8RtS579w9ej9mfCYK7VUdyCJPHK8AzW9zMsopGZEkYeNjAY7Zz1bkM7CGu8eKLzrjBLTMC5wWJDhxiK91ahA29rhDRsHdJDV2u2jFwb2MNUix8JW7sAkAqYVaJpCehTBPgRQ1KqKwqqUaNmuD8kazd4Q8MCWmgbWs21Yuomdqyi9FLigjRp7oY4m5adaVU19Nj1AHvsMY2tePeU2L')
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
static fromSpendingKey(spendingKey, password) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const decodedSpendingKey = helpers_1.decryptKey(spendingKey, password);
|
|
52
|
+
const provingKey = yield sapling.getProofAuthorizingKey(decodedSpendingKey);
|
|
53
|
+
return new InMemoryProvingKey(provingKey.toString('hex'));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @description Prepare an unsigned sapling spend description using the proving key
|
|
58
|
+
*
|
|
59
|
+
* @param parametersSpendProof.saplingContext The sapling proving context
|
|
60
|
+
* @param parametersSpendProof.address The address of the input
|
|
61
|
+
* @param parametersSpendProof.randomCommitmentTrapdoor The randomness of the commitment
|
|
62
|
+
* @param parametersSpendProof.publicKeyReRandomization The re-randomization of the public key
|
|
63
|
+
* @param parametersSpendProof.amount The value of the input
|
|
64
|
+
* @param parametersSpendProof.root The root of the merkle tree
|
|
65
|
+
* @param parametersSpendProof.witness The path of the commitment in the tree
|
|
66
|
+
* @param derivationPath tezos current standard 'm/'
|
|
67
|
+
* @returns The unsinged spend description
|
|
68
|
+
*/
|
|
69
|
+
prepareSpendDescription(parametersSpendProof) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const spendDescription = yield sapling.prepareSpendDescriptionWithAuthorizingKey(parametersSpendProof.saplingContext, __classPrivateFieldGet(this, _provingKey), parametersSpendProof.address, parametersSpendProof.randomCommitmentTrapdoor, parametersSpendProof.publicKeyReRandomization, parametersSpendProof.amount, parametersSpendProof.root, parametersSpendProof.witness);
|
|
72
|
+
return {
|
|
73
|
+
commitmentValue: spendDescription.cv,
|
|
74
|
+
nullifier: spendDescription.nf,
|
|
75
|
+
publicKeyReRandomization: spendDescription.rk,
|
|
76
|
+
rtAnchor: spendDescription.rt,
|
|
77
|
+
proof: spendDescription.proof,
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.InMemoryProvingKey = InMemoryProvingKey;
|
|
83
|
+
_provingKey = new WeakMap();
|
|
84
|
+
//# sourceMappingURL=in-memory-proving-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory-proving-key.js","sourceRoot":"","sources":["../../../src/sapling-keys/in-memory-proving-key.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAgD;AAEhD,uCAAuC;AAEvC;;;GAGG;AACH,MAAa,kBAAkB;IAG7B,YAAY,UAAkB;QAF9B,8BAAoB;QAGlB,uBAAA,IAAI,eAAe,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,EAAC;IACpD,CAAC;IAED;;;;;;;;;;OAUG;IACH,MAAM,CAAO,eAAe,CAAC,WAAmB,EAAE,QAAiB;;YACjE,MAAM,kBAAkB,GAAG,oBAAU,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;YAC7D,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,sBAAsB,CAAC,kBAAkB,CAAC,CAAC;YAC5E,OAAO,IAAI,kBAAkB,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;QAC5D,CAAC;KAAA;IAED;;;;;;;;;;;;OAYG;IACG,uBAAuB,CAC3B,oBAA+D;;YAE/D,MAAM,gBAAgB,GAAG,MAAM,OAAO,CAAC,yCAAyC,CAC9E,oBAAoB,CAAC,cAAc,6CAEnC,oBAAoB,CAAC,OAAO,EAC5B,oBAAoB,CAAC,wBAAwB,EAC7C,oBAAoB,CAAC,wBAAwB,EAC7C,oBAAoB,CAAC,MAAM,EAC3B,oBAAoB,CAAC,IAAI,EACzB,oBAAoB,CAAC,OAAO,CAC7B,CAAC;YACF,OAAO;gBACL,eAAe,EAAE,gBAAgB,CAAC,EAAE;gBACpC,SAAS,EAAE,gBAAgB,CAAC,EAAE;gBAC9B,wBAAwB,EAAE,gBAAgB,CAAC,EAAE;gBAC7C,QAAQ,EAAE,gBAAgB,CAAC,EAAE;gBAC7B,KAAK,EAAE,gBAAgB,CAAC,KAAK;aAC9B,CAAC;QACJ,CAAC;KAAA;CACF;AA1DD,gDA0DC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
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
|
+
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;
|
|
17
|
+
};
|
|
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);
|
|
23
|
+
};
|
|
24
|
+
var _spendingKeyBuf, _saplingViewingKey;
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.InMemorySpendingKey = void 0;
|
|
27
|
+
const error_1 = require("../error");
|
|
28
|
+
const in_memory_viewing_key_1 = require("./in-memory-viewing-key");
|
|
29
|
+
const sapling = require("@airgap/sapling-wasm");
|
|
30
|
+
const utils_1 = require("@taquito/utils");
|
|
31
|
+
const bip39 = require("bip39");
|
|
32
|
+
const helpers_1 = require("./helpers");
|
|
33
|
+
/**
|
|
34
|
+
* @description holds the spending key, create proof and signature for spend descriptions
|
|
35
|
+
* can instantiate from mnemonic word list or decrypt a encrypted spending key
|
|
36
|
+
* with access to instantiate a InMemoryViewingKey
|
|
37
|
+
*/
|
|
38
|
+
class InMemorySpendingKey {
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param spendingKey unencrypted sask... or encrypted MMXj...
|
|
42
|
+
* @param password required for MMXj encrypted keys
|
|
43
|
+
*/
|
|
44
|
+
constructor(spendingKey, password) {
|
|
45
|
+
_spendingKeyBuf.set(this, void 0);
|
|
46
|
+
_saplingViewingKey.set(this, void 0);
|
|
47
|
+
__classPrivateFieldSet(this, _spendingKeyBuf, helpers_1.decryptKey(spendingKey, password));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @param mnemonic string of words
|
|
52
|
+
* @param derivationPath tezos current standard 'm/'
|
|
53
|
+
* @returns InMemorySpendingKey class instantiated
|
|
54
|
+
*/
|
|
55
|
+
static fromMnemonic(mnemonic, derivationPath = 'm/') {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
// no password passed here. password provided only changes from sask -> MMXj
|
|
58
|
+
const fullSeed = yield bip39.mnemonicToSeed(mnemonic);
|
|
59
|
+
const first32 = fullSeed.slice(0, 32);
|
|
60
|
+
const second32 = fullSeed.slice(32);
|
|
61
|
+
// reduce seed bytes must be 32 bytes reflecting both halves
|
|
62
|
+
const seed = Buffer.from(first32.map((byte, index) => byte ^ second32[index]));
|
|
63
|
+
const spendingKeyArr = new Uint8Array(yield sapling.getExtendedSpendingKey(seed, derivationPath));
|
|
64
|
+
const spendingKey = utils_1.b58cencode(spendingKeyArr, utils_1.prefix[utils_1.Prefix.SASK]);
|
|
65
|
+
if (utils_1.ValidationResult.VALID !== 3) {
|
|
66
|
+
throw new error_1.InvalidSpendingKey(spendingKey);
|
|
67
|
+
}
|
|
68
|
+
return new InMemorySpendingKey(spendingKey);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
*
|
|
73
|
+
* @returns InMemoryViewingKey instantiated class
|
|
74
|
+
*/
|
|
75
|
+
getSaplingViewingKeyProvider() {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
let viewingKey;
|
|
78
|
+
if (!__classPrivateFieldGet(this, _saplingViewingKey)) {
|
|
79
|
+
viewingKey = yield sapling.getExtendedFullViewingKeyFromSpendingKey(__classPrivateFieldGet(this, _spendingKeyBuf));
|
|
80
|
+
__classPrivateFieldSet(this, _saplingViewingKey, new in_memory_viewing_key_1.InMemoryViewingKey(viewingKey.toString('hex')));
|
|
81
|
+
}
|
|
82
|
+
return __classPrivateFieldGet(this, _saplingViewingKey);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @description Prepare an unsigned sapling spend description using the spending key
|
|
87
|
+
* @param parametersSpendProof.saplingContext The sapling proving context
|
|
88
|
+
* @param parametersSpendProof.address The address of the input
|
|
89
|
+
* @param parametersSpendProof.randomCommitmentTrapdoor The randomness of the commitment
|
|
90
|
+
* @param parametersSpendProof.publicKeyReRandomization The re-randomization of the public key
|
|
91
|
+
* @param parametersSpendProof.amount The value of the input
|
|
92
|
+
* @param parametersSpendProof.root The root of the merkle tree
|
|
93
|
+
* @param parametersSpendProof.witness The path of the commitment in the tree
|
|
94
|
+
* @param derivationPath tezos current standard 'm/'
|
|
95
|
+
* @returns The unsigned spend description
|
|
96
|
+
*/
|
|
97
|
+
prepareSpendDescription(parametersSpendProof) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const spendDescription = yield sapling.prepareSpendDescriptionWithSpendingKey(parametersSpendProof.saplingContext, __classPrivateFieldGet(this, _spendingKeyBuf), parametersSpendProof.address, parametersSpendProof.randomCommitmentTrapdoor, parametersSpendProof.publicKeyReRandomization, parametersSpendProof.amount, parametersSpendProof.root, parametersSpendProof.witness);
|
|
100
|
+
return {
|
|
101
|
+
commitmentValue: spendDescription.cv,
|
|
102
|
+
nullifier: spendDescription.nf,
|
|
103
|
+
publicKeyReRandomization: spendDescription.rk,
|
|
104
|
+
rtAnchor: spendDescription.rt,
|
|
105
|
+
proof: spendDescription.proof,
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* @description Sign a sapling spend description
|
|
111
|
+
* @param parametersSpendSig.publicKeyReRandomization The re-randomization of the public key
|
|
112
|
+
* @param parametersSpendSig.unsignedSpendDescription The unsigned Spend description
|
|
113
|
+
* @param parametersSpendSig.hash The data to be signed
|
|
114
|
+
* @returns The signed spend description
|
|
115
|
+
*/
|
|
116
|
+
signSpendDescription(parametersSpendSig) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
const signedSpendDescription = yield sapling.signSpendDescription({
|
|
119
|
+
cv: parametersSpendSig.unsignedSpendDescription.commitmentValue,
|
|
120
|
+
rt: parametersSpendSig.unsignedSpendDescription.rtAnchor,
|
|
121
|
+
nf: parametersSpendSig.unsignedSpendDescription.nullifier,
|
|
122
|
+
rk: parametersSpendSig.unsignedSpendDescription.publicKeyReRandomization,
|
|
123
|
+
proof: parametersSpendSig.unsignedSpendDescription.proof,
|
|
124
|
+
}, __classPrivateFieldGet(this, _spendingKeyBuf), parametersSpendSig.publicKeyReRandomization, parametersSpendSig.hash);
|
|
125
|
+
return {
|
|
126
|
+
commitmentValue: signedSpendDescription.cv,
|
|
127
|
+
nullifier: signedSpendDescription.nf,
|
|
128
|
+
publicKeyReRandomization: signedSpendDescription.rk,
|
|
129
|
+
proof: signedSpendDescription.proof,
|
|
130
|
+
signature: signedSpendDescription.spendAuthSig,
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* @description Return a proof authorizing key from the configured spending key
|
|
136
|
+
*/
|
|
137
|
+
getProvingKey() {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
const provingKey = yield sapling.getProofAuthorizingKey(__classPrivateFieldGet(this, _spendingKeyBuf));
|
|
140
|
+
return provingKey.toString('hex');
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.InMemorySpendingKey = InMemorySpendingKey;
|
|
145
|
+
_spendingKeyBuf = new WeakMap(), _saplingViewingKey = new WeakMap();
|
|
146
|
+
//# sourceMappingURL=in-memory-spending-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory-spending-key.js","sourceRoot":"","sources":["../../../src/sapling-keys/in-memory-spending-key.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAA8C;AAC9C,mEAA6D;AAC7D,gDAAgD;AAChD,0CAA8E;AAC9E,+BAA+B;AAO/B,uCAAuC;AAEvC;;;;GAIG;AACH,MAAa,mBAAmB;IAG9B;;;;OAIG;IACH,YAAY,WAAmB,EAAE,QAAiB;QAPlD,kCAAwB;QACxB,qCAAmD;QAO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