@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
package/dist/lib/errors.js
CHANGED
|
@@ -4,21 +4,21 @@ exports.SaplingTransactionViewerError = exports.InsufficientBalance = exports.In
|
|
|
4
4
|
const core_1 = require("@taquito/core");
|
|
5
5
|
/**
|
|
6
6
|
* @category Error
|
|
7
|
-
*
|
|
7
|
+
* Error indicates the spending key is invalid
|
|
8
8
|
*/
|
|
9
9
|
class InvalidSpendingKey extends core_1.ParameterValidationError {
|
|
10
|
-
constructor(
|
|
10
|
+
constructor(a, b) {
|
|
11
|
+
const errorDetail = arguments.length >= 2 ? b : a;
|
|
11
12
|
super();
|
|
12
|
-
this.sk = sk;
|
|
13
|
-
this.errorDetail = errorDetail;
|
|
14
13
|
this.name = 'InvalidSpendingKey';
|
|
15
|
-
this.
|
|
14
|
+
this.errorDetail = errorDetail;
|
|
15
|
+
this.message = `Invalid spending key: ${errorDetail}.`;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
exports.InvalidSpendingKey = InvalidSpendingKey;
|
|
19
19
|
/**
|
|
20
20
|
* @category Error
|
|
21
|
-
*
|
|
21
|
+
* Error indicates an invalid Merkle tree being passed
|
|
22
22
|
*/
|
|
23
23
|
class InvalidMerkleTreeError extends core_1.ParameterValidationError {
|
|
24
24
|
constructor(root) {
|
|
@@ -31,7 +31,7 @@ class InvalidMerkleTreeError extends core_1.ParameterValidationError {
|
|
|
31
31
|
exports.InvalidMerkleTreeError = InvalidMerkleTreeError;
|
|
32
32
|
/**
|
|
33
33
|
* @category Error
|
|
34
|
-
*
|
|
34
|
+
* Error indicates a failure when trying to construct the Merkle tree
|
|
35
35
|
*/
|
|
36
36
|
class TreeConstructionFailure extends core_1.TaquitoError {
|
|
37
37
|
constructor(message) {
|
|
@@ -43,7 +43,7 @@ class TreeConstructionFailure extends core_1.TaquitoError {
|
|
|
43
43
|
exports.TreeConstructionFailure = TreeConstructionFailure;
|
|
44
44
|
/**
|
|
45
45
|
* @category Error
|
|
46
|
-
*
|
|
46
|
+
* Error indicates the memo is invalid
|
|
47
47
|
*/
|
|
48
48
|
class InvalidMemo extends core_1.ParameterValidationError {
|
|
49
49
|
constructor(memo, errorDetails) {
|
|
@@ -57,7 +57,7 @@ class InvalidMemo extends core_1.ParameterValidationError {
|
|
|
57
57
|
exports.InvalidMemo = InvalidMemo;
|
|
58
58
|
/**
|
|
59
59
|
* @category Error
|
|
60
|
-
*
|
|
60
|
+
* Error indicates not enough balance to prepare the sapling transaction
|
|
61
61
|
*/
|
|
62
62
|
class InsufficientBalance extends core_1.TaquitoError {
|
|
63
63
|
constructor(realBalance, amountToSpend) {
|
|
@@ -71,7 +71,7 @@ class InsufficientBalance extends core_1.TaquitoError {
|
|
|
71
71
|
exports.InsufficientBalance = InsufficientBalance;
|
|
72
72
|
/**
|
|
73
73
|
* @category Error
|
|
74
|
-
*
|
|
74
|
+
* Error indicates SaplingTransactionViewer failure
|
|
75
75
|
*/
|
|
76
76
|
class SaplingTransactionViewerError extends core_1.TaquitoError {
|
|
77
77
|
constructor(message) {
|
|
@@ -5,7 +5,7 @@ const utils_1 = require("@taquito/utils");
|
|
|
5
5
|
const bignumber_js_1 = require("bignumber.js");
|
|
6
6
|
class SaplingForger {
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Forge sapling transactions
|
|
9
9
|
* @param spendDescriptions the list of spend descriptions
|
|
10
10
|
* @param outputDescriptions the list of output descriptions
|
|
11
11
|
* @param signature signature hash
|
|
@@ -30,7 +30,7 @@ class SaplingForger {
|
|
|
30
30
|
]);
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* Forge list of spend descriptions
|
|
34
34
|
* @param spendDescriptions list of spend descriptions
|
|
35
35
|
* @returns concatenated forged bytes of type Buffer
|
|
36
36
|
*/
|
|
@@ -52,7 +52,7 @@ class SaplingForger {
|
|
|
52
52
|
]);
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
55
|
+
* Forge list of output descriptions
|
|
56
56
|
* @param outputDescriptions list of output descriptions
|
|
57
57
|
* @returns concatenated forged bytes of type Buffer
|
|
58
58
|
*/
|
|
@@ -17,7 +17,7 @@ function decryptKey(spendingKey, password) {
|
|
|
17
17
|
}
|
|
18
18
|
catch (err) {
|
|
19
19
|
if (err instanceof core_1.ParameterValidationError) {
|
|
20
|
-
throw new errors_1.InvalidSpendingKey(
|
|
20
|
+
throw new errors_1.InvalidSpendingKey('invalid spending key');
|
|
21
21
|
}
|
|
22
22
|
else {
|
|
23
23
|
throw err;
|
|
@@ -26,7 +26,7 @@ function decryptKey(spendingKey, password) {
|
|
|
26
26
|
})();
|
|
27
27
|
if (pre === utils_1.PrefixV2.EncryptedSaplingSpendingKey) {
|
|
28
28
|
if (!password) {
|
|
29
|
-
throw new errors_1.InvalidSpendingKey(
|
|
29
|
+
throw new errors_1.InvalidSpendingKey('no password provided to decrypt');
|
|
30
30
|
}
|
|
31
31
|
const salt = (0, typedarray_to_buffer_1.default)(keyArr.slice(0, 8));
|
|
32
32
|
const encryptedSk = (0, typedarray_to_buffer_1.default)(keyArr.slice(8));
|
|
@@ -36,7 +36,7 @@ function decryptKey(spendingKey, password) {
|
|
|
36
36
|
const decrypted = (0, nacl_1.openSecretBox)(new Uint8Array(encryptionKey), new Uint8Array(24), // zero nonce - uniqueness provided by per-encryption derived key
|
|
37
37
|
new Uint8Array(encryptedSk));
|
|
38
38
|
if (!decrypted) {
|
|
39
|
-
throw new errors_1.InvalidSpendingKey(
|
|
39
|
+
throw new errors_1.InvalidSpendingKey('incorrect password or unable to decrypt');
|
|
40
40
|
}
|
|
41
41
|
return (0, typedarray_to_buffer_1.default)(decrypted);
|
|
42
42
|
}
|
|
@@ -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");
|
|
@@ -25,7 +16,7 @@ exports.InMemoryProvingKey = void 0;
|
|
|
25
16
|
const sapling = require("@airgap/sapling-wasm");
|
|
26
17
|
const helpers_1 = require("./helpers");
|
|
27
18
|
/**
|
|
28
|
-
*
|
|
19
|
+
* holds the proving key, create proof for spend descriptions
|
|
29
20
|
* The class can be instantiated from a proving key or a spending key
|
|
30
21
|
*/
|
|
31
22
|
class InMemoryProvingKey {
|
|
@@ -34,7 +25,7 @@ class InMemoryProvingKey {
|
|
|
34
25
|
__classPrivateFieldSet(this, _InMemoryProvingKey_provingKey, Buffer.from(provingKey, 'hex'), "f");
|
|
35
26
|
}
|
|
36
27
|
/**
|
|
37
|
-
*
|
|
28
|
+
* Allows to instantiate the InMemoryProvingKey from an encrypted/unencrypted spending key
|
|
38
29
|
*
|
|
39
30
|
* @param spendingKey Base58Check-encoded spending key
|
|
40
31
|
* @param password Optional password to decrypt the spending key
|
|
@@ -44,15 +35,13 @@ class InMemoryProvingKey {
|
|
|
44
35
|
* ```
|
|
45
36
|
*
|
|
46
37
|
*/
|
|
47
|
-
static fromSpendingKey(spendingKey, password) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return new InMemoryProvingKey(provingKey.toString('hex'));
|
|
52
|
-
});
|
|
38
|
+
static async fromSpendingKey(spendingKey, password) {
|
|
39
|
+
const decodedSpendingKey = (0, helpers_1.decryptKey)(spendingKey, password);
|
|
40
|
+
const provingKey = await sapling.getProofAuthorizingKey(decodedSpendingKey);
|
|
41
|
+
return new InMemoryProvingKey(provingKey.toString('hex'));
|
|
53
42
|
}
|
|
54
43
|
/**
|
|
55
|
-
*
|
|
44
|
+
* Prepare an unsigned sapling spend description using the proving key
|
|
56
45
|
*
|
|
57
46
|
* @param parametersSpendProof.saplingContext The sapling proving context
|
|
58
47
|
* @param parametersSpendProof.address The address of the input
|
|
@@ -61,20 +50,17 @@ class InMemoryProvingKey {
|
|
|
61
50
|
* @param parametersSpendProof.amount The value of the input
|
|
62
51
|
* @param parametersSpendProof.root The root of the merkle tree
|
|
63
52
|
* @param parametersSpendProof.witness The path of the commitment in the tree
|
|
64
|
-
* @param derivationPath tezos current standard 'm/'
|
|
65
53
|
* @returns The unsinged spend description
|
|
66
54
|
*/
|
|
67
|
-
prepareSpendDescription(parametersSpendProof) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
};
|
|
77
|
-
});
|
|
55
|
+
async prepareSpendDescription(parametersSpendProof) {
|
|
56
|
+
const spendDescription = await sapling.prepareSpendDescriptionWithAuthorizingKey(parametersSpendProof.saplingContext, __classPrivateFieldGet(this, _InMemoryProvingKey_provingKey, "f"), parametersSpendProof.address, parametersSpendProof.randomCommitmentTrapdoor, parametersSpendProof.publicKeyReRandomization, parametersSpendProof.amount, parametersSpendProof.root, parametersSpendProof.witness);
|
|
57
|
+
return {
|
|
58
|
+
commitmentValue: spendDescription.cv,
|
|
59
|
+
nullifier: spendDescription.nf,
|
|
60
|
+
publicKeyReRandomization: spendDescription.rk,
|
|
61
|
+
rtAnchor: spendDescription.rt,
|
|
62
|
+
proof: spendDescription.proof,
|
|
63
|
+
};
|
|
78
64
|
}
|
|
79
65
|
}
|
|
80
66
|
exports.InMemoryProvingKey = InMemoryProvingKey;
|
|
@@ -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");
|
|
@@ -28,7 +19,7 @@ const utils_1 = require("@taquito/utils");
|
|
|
28
19
|
const bip39 = require("bip39");
|
|
29
20
|
const helpers_1 = require("./helpers");
|
|
30
21
|
/**
|
|
31
|
-
*
|
|
22
|
+
* holds the spending key, create proof and signature for spend descriptions
|
|
32
23
|
* can instantiate from mnemonic word list or decrypt a encrypted spending key
|
|
33
24
|
* with access to instantiate a InMemoryViewingKey
|
|
34
25
|
*/
|
|
@@ -49,35 +40,31 @@ class InMemorySpendingKey {
|
|
|
49
40
|
* @param derivationPath tezos current standard 'm/'
|
|
50
41
|
* @returns InMemorySpendingKey class instantiated
|
|
51
42
|
*/
|
|
52
|
-
static fromMnemonic(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return new InMemorySpendingKey(spendingKey);
|
|
63
|
-
});
|
|
43
|
+
static async fromMnemonic(mnemonic, derivationPath = 'm/') {
|
|
44
|
+
// no password passed here. password provided only changes from sask -> MMXj
|
|
45
|
+
const fullSeed = await bip39.mnemonicToSeed(mnemonic);
|
|
46
|
+
const first32 = fullSeed.slice(0, 32);
|
|
47
|
+
const second32 = fullSeed.slice(32);
|
|
48
|
+
// reduce seed bytes must be 32 bytes reflecting both halves
|
|
49
|
+
const seed = Buffer.from(first32.map((byte, index) => byte ^ second32[index]));
|
|
50
|
+
const spendingKeyArr = new Uint8Array(await sapling.getExtendedSpendingKey(seed, derivationPath));
|
|
51
|
+
const spendingKey = (0, utils_1.b58Encode)(spendingKeyArr, utils_1.PrefixV2.SaplingSpendingKey);
|
|
52
|
+
return new InMemorySpendingKey(spendingKey);
|
|
64
53
|
}
|
|
65
54
|
/**
|
|
66
55
|
*
|
|
67
56
|
* @returns InMemoryViewingKey instantiated class
|
|
68
57
|
*/
|
|
69
|
-
getSaplingViewingKeyProvider() {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return __classPrivateFieldGet(this, _InMemorySpendingKey_saplingViewingKey, "f");
|
|
77
|
-
});
|
|
58
|
+
async getSaplingViewingKeyProvider() {
|
|
59
|
+
let viewingKey;
|
|
60
|
+
if (!__classPrivateFieldGet(this, _InMemorySpendingKey_saplingViewingKey, "f")) {
|
|
61
|
+
viewingKey = await sapling.getExtendedFullViewingKeyFromSpendingKey(__classPrivateFieldGet(this, _InMemorySpendingKey_spendingKeyBuf, "f"));
|
|
62
|
+
__classPrivateFieldSet(this, _InMemorySpendingKey_saplingViewingKey, new in_memory_viewing_key_1.InMemoryViewingKey(viewingKey.toString('hex')), "f");
|
|
63
|
+
}
|
|
64
|
+
return __classPrivateFieldGet(this, _InMemorySpendingKey_saplingViewingKey, "f");
|
|
78
65
|
}
|
|
79
66
|
/**
|
|
80
|
-
*
|
|
67
|
+
* Prepare an unsigned sapling spend description using the spending key
|
|
81
68
|
* @param parametersSpendProof.saplingContext The sapling proving context
|
|
82
69
|
* @param parametersSpendProof.address The address of the input
|
|
83
70
|
* @param parametersSpendProof.randomCommitmentTrapdoor The randomness of the commitment
|
|
@@ -85,54 +72,47 @@ class InMemorySpendingKey {
|
|
|
85
72
|
* @param parametersSpendProof.amount The value of the input
|
|
86
73
|
* @param parametersSpendProof.root The root of the merkle tree
|
|
87
74
|
* @param parametersSpendProof.witness The path of the commitment in the tree
|
|
88
|
-
* @param derivationPath tezos current standard 'm/'
|
|
89
75
|
* @returns The unsigned spend description
|
|
90
76
|
*/
|
|
91
|
-
prepareSpendDescription(parametersSpendProof) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
};
|
|
101
|
-
});
|
|
77
|
+
async prepareSpendDescription(parametersSpendProof) {
|
|
78
|
+
const spendDescription = await sapling.prepareSpendDescriptionWithSpendingKey(parametersSpendProof.saplingContext, __classPrivateFieldGet(this, _InMemorySpendingKey_spendingKeyBuf, "f"), parametersSpendProof.address, parametersSpendProof.randomCommitmentTrapdoor, parametersSpendProof.publicKeyReRandomization, parametersSpendProof.amount, parametersSpendProof.root, parametersSpendProof.witness);
|
|
79
|
+
return {
|
|
80
|
+
commitmentValue: spendDescription.cv,
|
|
81
|
+
nullifier: spendDescription.nf,
|
|
82
|
+
publicKeyReRandomization: spendDescription.rk,
|
|
83
|
+
rtAnchor: spendDescription.rt,
|
|
84
|
+
proof: spendDescription.proof,
|
|
85
|
+
};
|
|
102
86
|
}
|
|
103
87
|
/**
|
|
104
|
-
*
|
|
88
|
+
* Sign a sapling spend description
|
|
105
89
|
* @param parametersSpendSig.publicKeyReRandomization The re-randomization of the public key
|
|
106
90
|
* @param parametersSpendSig.unsignedSpendDescription The unsigned Spend description
|
|
107
91
|
* @param parametersSpendSig.hash The data to be signed
|
|
108
92
|
* @returns The signed spend description
|
|
109
93
|
*/
|
|
110
|
-
signSpendDescription(parametersSpendSig) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
};
|
|
126
|
-
});
|
|
94
|
+
async signSpendDescription(parametersSpendSig) {
|
|
95
|
+
const signedSpendDescription = await sapling.signSpendDescription({
|
|
96
|
+
cv: parametersSpendSig.unsignedSpendDescription.commitmentValue,
|
|
97
|
+
rt: parametersSpendSig.unsignedSpendDescription.rtAnchor,
|
|
98
|
+
nf: parametersSpendSig.unsignedSpendDescription.nullifier,
|
|
99
|
+
rk: parametersSpendSig.unsignedSpendDescription.publicKeyReRandomization,
|
|
100
|
+
proof: parametersSpendSig.unsignedSpendDescription.proof,
|
|
101
|
+
}, __classPrivateFieldGet(this, _InMemorySpendingKey_spendingKeyBuf, "f"), parametersSpendSig.publicKeyReRandomization, parametersSpendSig.hash);
|
|
102
|
+
return {
|
|
103
|
+
commitmentValue: signedSpendDescription.cv,
|
|
104
|
+
nullifier: signedSpendDescription.nf,
|
|
105
|
+
publicKeyReRandomization: signedSpendDescription.rk,
|
|
106
|
+
proof: signedSpendDescription.proof,
|
|
107
|
+
signature: signedSpendDescription.spendAuthSig,
|
|
108
|
+
};
|
|
127
109
|
}
|
|
128
110
|
/**
|
|
129
|
-
*
|
|
111
|
+
* Return a proof authorizing key from the configured spending key
|
|
130
112
|
*/
|
|
131
|
-
getProvingKey() {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return provingKey.toString('hex');
|
|
135
|
-
});
|
|
113
|
+
async getProvingKey() {
|
|
114
|
+
const provingKey = await sapling.getProofAuthorizingKey(__classPrivateFieldGet(this, _InMemorySpendingKey_spendingKeyBuf, "f"));
|
|
115
|
+
return provingKey.toString('hex');
|
|
136
116
|
}
|
|
137
117
|
}
|
|
138
118
|
exports.InMemorySpendingKey = InMemorySpendingKey;
|
|
@@ -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");
|
|
@@ -26,7 +17,7 @@ const utils_1 = require("@taquito/utils");
|
|
|
26
17
|
const sapling = require("@airgap/sapling-wasm");
|
|
27
18
|
const helpers_1 = require("./helpers");
|
|
28
19
|
/**
|
|
29
|
-
*
|
|
20
|
+
* Holds the viewing key
|
|
30
21
|
*/
|
|
31
22
|
class InMemoryViewingKey {
|
|
32
23
|
constructor(fullViewingKey) {
|
|
@@ -34,7 +25,7 @@ class InMemoryViewingKey {
|
|
|
34
25
|
__classPrivateFieldSet(this, _InMemoryViewingKey_fullViewingKey, Buffer.from(fullViewingKey, 'hex'), "f");
|
|
35
26
|
}
|
|
36
27
|
/**
|
|
37
|
-
*
|
|
28
|
+
* Allows to instantiate the InMemoryViewingKey from an encrypted/unencrypted spending key
|
|
38
29
|
*
|
|
39
30
|
* @param spendingKey Base58Check-encoded spending key
|
|
40
31
|
* @param password Optional password to decrypt the spending key
|
|
@@ -44,15 +35,13 @@ class InMemoryViewingKey {
|
|
|
44
35
|
* ```
|
|
45
36
|
*
|
|
46
37
|
*/
|
|
47
|
-
static fromSpendingKey(spendingKey, password) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return new InMemoryViewingKey(viewingKey.toString('hex'));
|
|
52
|
-
});
|
|
38
|
+
static async fromSpendingKey(spendingKey, password) {
|
|
39
|
+
const spendingKeyBuf = (0, helpers_1.decryptKey)(spendingKey, password);
|
|
40
|
+
const viewingKey = await sapling.getExtendedFullViewingKeyFromSpendingKey(spendingKeyBuf);
|
|
41
|
+
return new InMemoryViewingKey(viewingKey.toString('hex'));
|
|
53
42
|
}
|
|
54
43
|
/**
|
|
55
|
-
*
|
|
44
|
+
* Retrieve the full viewing key
|
|
56
45
|
* @returns Buffer representing the full viewing key
|
|
57
46
|
*
|
|
58
47
|
*/
|
|
@@ -60,39 +49,33 @@ class InMemoryViewingKey {
|
|
|
60
49
|
return __classPrivateFieldGet(this, _InMemoryViewingKey_fullViewingKey, "f");
|
|
61
50
|
}
|
|
62
51
|
/**
|
|
63
|
-
*
|
|
52
|
+
* Retrieve the outgoing viewing key
|
|
64
53
|
* @returns Buffer representing the outgoing viewing key
|
|
65
54
|
*
|
|
66
55
|
*/
|
|
67
|
-
getOutgoingViewingKey() {
|
|
68
|
-
return
|
|
69
|
-
return sapling.getOutgoingViewingKey(__classPrivateFieldGet(this, _InMemoryViewingKey_fullViewingKey, "f"));
|
|
70
|
-
});
|
|
56
|
+
async getOutgoingViewingKey() {
|
|
57
|
+
return sapling.getOutgoingViewingKey(__classPrivateFieldGet(this, _InMemoryViewingKey_fullViewingKey, "f"));
|
|
71
58
|
}
|
|
72
59
|
/**
|
|
73
|
-
*
|
|
60
|
+
* Retrieve the incoming viewing key
|
|
74
61
|
* @returns Buffer representing the incoming viewing key
|
|
75
62
|
*
|
|
76
63
|
*/
|
|
77
|
-
getIncomingViewingKey() {
|
|
78
|
-
return
|
|
79
|
-
return sapling.getIncomingViewingKey(__classPrivateFieldGet(this, _InMemoryViewingKey_fullViewingKey, "f"));
|
|
80
|
-
});
|
|
64
|
+
async getIncomingViewingKey() {
|
|
65
|
+
return sapling.getIncomingViewingKey(__classPrivateFieldGet(this, _InMemoryViewingKey_fullViewingKey, "f"));
|
|
81
66
|
}
|
|
82
67
|
/**
|
|
83
|
-
*
|
|
68
|
+
* Retrieve a payment address
|
|
84
69
|
* @param addressIndex used to determine which diversifier should be used to derive the address, default is 0
|
|
85
70
|
* @returns Base58Check-encoded address and its index
|
|
86
71
|
*
|
|
87
72
|
*/
|
|
88
|
-
getAddress(addressIndex) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
};
|
|
95
|
-
});
|
|
73
|
+
async getAddress(addressIndex) {
|
|
74
|
+
const { index, raw } = await sapling.getPaymentAddressFromViewingKey(__classPrivateFieldGet(this, _InMemoryViewingKey_fullViewingKey, "f"), addressIndex);
|
|
75
|
+
return {
|
|
76
|
+
address: (0, utils_1.b58Encode)(raw, utils_1.PrefixV2.SaplingAddress),
|
|
77
|
+
addressIndex: index.readInt32LE(),
|
|
78
|
+
};
|
|
96
79
|
}
|
|
97
80
|
}
|
|
98
81
|
exports.InMemoryViewingKey = InMemoryViewingKey;
|
|
@@ -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
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.SaplingWrapper = void 0;
|
|
13
4
|
const sapling = require("@airgap/sapling-wasm");
|
|
@@ -16,67 +7,52 @@ const random_1 = require("@stablelib/random");
|
|
|
16
7
|
const saplingOutputParams = require('../saplingOutputParams');
|
|
17
8
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
18
9
|
const saplingSpendParams = require('../saplingSpendParams');
|
|
10
|
+
let cachedParams;
|
|
19
11
|
class SaplingWrapper {
|
|
20
|
-
withProvingContext(action) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return sapling.withProvingContext(action);
|
|
24
|
-
});
|
|
12
|
+
async withProvingContext(action) {
|
|
13
|
+
await this.initSaplingParameters();
|
|
14
|
+
return sapling.withProvingContext(action);
|
|
25
15
|
}
|
|
26
16
|
getRandomBytes(length) {
|
|
27
17
|
return (0, random_1.randomBytes)(length);
|
|
28
18
|
}
|
|
29
|
-
randR() {
|
|
30
|
-
return
|
|
31
|
-
return sapling.randR();
|
|
32
|
-
});
|
|
19
|
+
async randR() {
|
|
20
|
+
return sapling.randR();
|
|
33
21
|
}
|
|
34
|
-
getOutgoingViewingKey(vk) {
|
|
35
|
-
return
|
|
36
|
-
return sapling.getOutgoingViewingKey(vk);
|
|
37
|
-
});
|
|
22
|
+
async getOutgoingViewingKey(vk) {
|
|
23
|
+
return sapling.getOutgoingViewingKey(vk);
|
|
38
24
|
}
|
|
39
|
-
preparePartialOutputDescription(parametersOutputProof) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
};
|
|
47
|
-
});
|
|
25
|
+
async preparePartialOutputDescription(parametersOutputProof) {
|
|
26
|
+
const partialOutputDesc = await sapling.preparePartialOutputDescription(parametersOutputProof.saplingContext, parametersOutputProof.address, parametersOutputProof.randomCommitmentTrapdoor, parametersOutputProof.ephemeralPrivateKey, parametersOutputProof.amount);
|
|
27
|
+
return {
|
|
28
|
+
commitmentValue: partialOutputDesc.cv,
|
|
29
|
+
commitment: partialOutputDesc.cm,
|
|
30
|
+
proof: partialOutputDesc.proof,
|
|
31
|
+
};
|
|
48
32
|
}
|
|
49
|
-
getDiversifiedFromRawPaymentAddress(decodedDestination) {
|
|
50
|
-
return
|
|
51
|
-
return sapling.getDiversifiedFromRawPaymentAddress(decodedDestination);
|
|
52
|
-
});
|
|
33
|
+
async getDiversifiedFromRawPaymentAddress(decodedDestination) {
|
|
34
|
+
return sapling.getDiversifiedFromRawPaymentAddress(decodedDestination);
|
|
53
35
|
}
|
|
54
|
-
deriveEphemeralPublicKey(diversifier, esk) {
|
|
55
|
-
return
|
|
56
|
-
return sapling.deriveEphemeralPublicKey(diversifier, esk);
|
|
57
|
-
});
|
|
36
|
+
async deriveEphemeralPublicKey(diversifier, esk) {
|
|
37
|
+
return sapling.deriveEphemeralPublicKey(diversifier, esk);
|
|
58
38
|
}
|
|
59
|
-
getPkdFromRawPaymentAddress(destination) {
|
|
60
|
-
return
|
|
61
|
-
return sapling.getPkdFromRawPaymentAddress(destination);
|
|
62
|
-
});
|
|
39
|
+
async getPkdFromRawPaymentAddress(destination) {
|
|
40
|
+
return sapling.getPkdFromRawPaymentAddress(destination);
|
|
63
41
|
}
|
|
64
|
-
keyAgreement(p, sk) {
|
|
65
|
-
return
|
|
66
|
-
return sapling.keyAgreement(p, sk);
|
|
67
|
-
});
|
|
42
|
+
async keyAgreement(p, sk) {
|
|
43
|
+
return sapling.keyAgreement(p, sk);
|
|
68
44
|
}
|
|
69
|
-
createBindingSignature(saplingContext, balance, transactionSigHash) {
|
|
70
|
-
return
|
|
71
|
-
return sapling.createBindingSignature(saplingContext, balance, transactionSigHash);
|
|
72
|
-
});
|
|
45
|
+
async createBindingSignature(saplingContext, balance, transactionSigHash) {
|
|
46
|
+
return sapling.createBindingSignature(saplingContext, balance, transactionSigHash);
|
|
73
47
|
}
|
|
74
|
-
initSaplingParameters() {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
48
|
+
async initSaplingParameters() {
|
|
49
|
+
if (!cachedParams) {
|
|
50
|
+
cachedParams = {
|
|
51
|
+
spend: Buffer.from(saplingSpendParams.saplingSpendParams, 'base64'),
|
|
52
|
+
output: Buffer.from(saplingOutputParams.saplingOutputParams, 'base64'),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return sapling.initParameters(cachedParams.spend, cachedParams.output);
|
|
80
56
|
}
|
|
81
57
|
}
|
|
82
58
|
exports.SaplingWrapper = SaplingWrapper;
|