@zill-protocol/client 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +18 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/package.json +58 -0
  7. package/dist/src/NocturneClient.d.ts +68 -0
  8. package/dist/src/NocturneClient.d.ts.map +1 -0
  9. package/dist/src/NocturneClient.js +264 -0
  10. package/dist/src/NocturneClient.js.map +1 -0
  11. package/dist/src/NocturneDB.d.ts +100 -0
  12. package/dist/src/NocturneDB.d.ts.map +1 -0
  13. package/dist/src/NocturneDB.js +525 -0
  14. package/dist/src/NocturneDB.js.map +1 -0
  15. package/dist/src/OpTracker.d.ts +13 -0
  16. package/dist/src/OpTracker.d.ts.map +1 -0
  17. package/dist/src/OpTracker.js +34 -0
  18. package/dist/src/OpTracker.js.map +1 -0
  19. package/dist/src/conversion/converter.d.ts +5 -0
  20. package/dist/src/conversion/converter.d.ts.map +1 -0
  21. package/dist/src/conversion/converter.js +15 -0
  22. package/dist/src/conversion/converter.js.map +1 -0
  23. package/dist/src/conversion/index.d.ts +3 -0
  24. package/dist/src/conversion/index.d.ts.map +1 -0
  25. package/dist/src/conversion/index.js +21 -0
  26. package/dist/src/conversion/index.js.map +1 -0
  27. package/dist/src/conversion/mock.d.ts +6 -0
  28. package/dist/src/conversion/mock.d.ts.map +1 -0
  29. package/dist/src/conversion/mock.js +14 -0
  30. package/dist/src/conversion/mock.js.map +1 -0
  31. package/dist/src/index.d.ts +14 -0
  32. package/dist/src/index.d.ts.map +1 -0
  33. package/dist/src/index.js +39 -0
  34. package/dist/src/index.js.map +1 -0
  35. package/dist/src/opRequestGas.d.ts +20 -0
  36. package/dist/src/opRequestGas.d.ts.map +1 -0
  37. package/dist/src/opRequestGas.js +321 -0
  38. package/dist/src/opRequestGas.js.map +1 -0
  39. package/dist/src/operationRequest/builder.d.ts +40 -0
  40. package/dist/src/operationRequest/builder.d.ts.map +1 -0
  41. package/dist/src/operationRequest/builder.js +192 -0
  42. package/dist/src/operationRequest/builder.js.map +1 -0
  43. package/dist/src/operationRequest/index.d.ts +3 -0
  44. package/dist/src/operationRequest/index.d.ts.map +1 -0
  45. package/dist/src/operationRequest/index.js +6 -0
  46. package/dist/src/operationRequest/index.js.map +1 -0
  47. package/dist/src/operationRequest/operationRequest.d.ts +50 -0
  48. package/dist/src/operationRequest/operationRequest.d.ts.map +1 -0
  49. package/dist/src/operationRequest/operationRequest.js +16 -0
  50. package/dist/src/operationRequest/operationRequest.js.map +1 -0
  51. package/dist/src/prepareOperation.d.ts +21 -0
  52. package/dist/src/prepareOperation.d.ts.map +1 -0
  53. package/dist/src/prepareOperation.js +256 -0
  54. package/dist/src/prepareOperation.js.map +1 -0
  55. package/dist/src/proveOperation.d.ts +7 -0
  56. package/dist/src/proveOperation.d.ts.map +1 -0
  57. package/dist/src/proveOperation.js +79 -0
  58. package/dist/src/proveOperation.js.map +1 -0
  59. package/dist/src/signOperation.d.ts +3 -0
  60. package/dist/src/signOperation.d.ts.map +1 -0
  61. package/dist/src/signOperation.js +61 -0
  62. package/dist/src/signOperation.js.map +1 -0
  63. package/dist/src/snapJsonRpc.d.ts +55 -0
  64. package/dist/src/snapJsonRpc.d.ts.map +1 -0
  65. package/dist/src/snapJsonRpc.js +63 -0
  66. package/dist/src/snapJsonRpc.js.map +1 -0
  67. package/dist/src/syncSDK.d.ts +17 -0
  68. package/dist/src/syncSDK.d.ts.map +1 -0
  69. package/dist/src/syncSDK.js +188 -0
  70. package/dist/src/syncSDK.js.map +1 -0
  71. package/dist/src/types.d.ts +60 -0
  72. package/dist/src/types.d.ts.map +1 -0
  73. package/dist/src/types.js +3 -0
  74. package/dist/src/types.js.map +1 -0
  75. package/dist/src/utils/constants.d.ts +3 -0
  76. package/dist/src/utils/constants.d.ts.map +1 -0
  77. package/dist/src/utils/constants.js +20 -0
  78. package/dist/src/utils/constants.js.map +1 -0
  79. package/dist/src/utils/index.d.ts +3 -0
  80. package/dist/src/utils/index.d.ts.map +1 -0
  81. package/dist/src/utils/index.js +19 -0
  82. package/dist/src/utils/index.js.map +1 -0
  83. package/dist/src/utils/misc.d.ts +13 -0
  84. package/dist/src/utils/misc.d.ts.map +1 -0
  85. package/dist/src/utils/misc.js +77 -0
  86. package/dist/src/utils/misc.js.map +1 -0
  87. package/dist/tsconfig.tsbuildinfo +1 -0
  88. package/package.json +58 -0
  89. package/src/NocturneClient.ts +415 -0
  90. package/src/NocturneDB.ts +761 -0
  91. package/src/OpTracker.ts +44 -0
  92. package/src/conversion/converter.ts +22 -0
  93. package/src/conversion/index.ts +2 -0
  94. package/src/conversion/mock.ts +11 -0
  95. package/src/index.ts +14 -0
  96. package/src/opRequestGas.ts +487 -0
  97. package/src/operationRequest/builder.ts +359 -0
  98. package/src/operationRequest/index.ts +16 -0
  99. package/src/operationRequest/operationRequest.ts +87 -0
  100. package/src/prepareOperation.ts +420 -0
  101. package/src/proveOperation.ts +124 -0
  102. package/src/signOperation.ts +116 -0
  103. package/src/snapJsonRpc.ts +109 -0
  104. package/src/syncSDK.ts +285 -0
  105. package/src/types.ts +83 -0
  106. package/src/utils/constants.ts +16 -0
  107. package/src/utils/index.ts +2 -0
  108. package/src/utils/misc.ts +107 -0
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.newOpRequestBuilder = newOpRequestBuilder;
4
+ const config_1 = require("@zill-protocol/config");
5
+ const core_1 = require("@zill-protocol/core");
6
+ const ethers_1 = require("ethers");
7
+ const constants_1 = require("../utils/constants");
8
+ // the base OpRequestBuilder. This is the only thing users should explicitly construct.
9
+ // to add functionality (erc20s, protocol integrations, etc), user should call `.use(plugin)` with the relevant plugin
10
+ function newOpRequestBuilder(provider, chainId, config // use override config instead of defaulting to builtin for chainid (for testing purposes)
11
+ ) {
12
+ if (!config) {
13
+ const networkName = (0, constants_1.chainIdToNetworkName)(chainId);
14
+ config = (0, config_1.loadNocturneConfigBuiltin)(networkName);
15
+ }
16
+ const _op = {
17
+ chainId,
18
+ tellerContract: config.tellerAddress,
19
+ joinSplitRequests: [],
20
+ refunds: [],
21
+ actions: [],
22
+ deadline: 0n,
23
+ };
24
+ const _builderItemsToProcess = [];
25
+ return {
26
+ provider,
27
+ config,
28
+ _op,
29
+ _builderItemsToProcess,
30
+ use(plugin) {
31
+ return plugin(this);
32
+ },
33
+ pluginFn(pluginPromise) {
34
+ this._builderItemsToProcess.push(pluginPromise);
35
+ return this;
36
+ },
37
+ __action(contractAddress, encodedFunction) {
38
+ const action = {
39
+ contractAddress: ethers_1.ethers.utils.getAddress(contractAddress),
40
+ encodedFunction,
41
+ };
42
+ this._builderItemsToProcess.push(Promise.resolve({
43
+ unwraps: [],
44
+ confidentialPayments: [],
45
+ refunds: [],
46
+ actions: [action],
47
+ metadatas: [],
48
+ }));
49
+ return this;
50
+ },
51
+ __unwrap(asset, amountUnits) {
52
+ const unwrap = {
53
+ asset,
54
+ unwrapValue: amountUnits,
55
+ };
56
+ this._builderItemsToProcess.push(Promise.resolve({
57
+ unwraps: [unwrap],
58
+ confidentialPayments: [],
59
+ refunds: [],
60
+ actions: [],
61
+ metadatas: [],
62
+ }));
63
+ return this;
64
+ },
65
+ confidentialPayment(asset, amountUnits, receiver) {
66
+ const payment = {
67
+ value: amountUnits,
68
+ receiver,
69
+ asset,
70
+ };
71
+ this._builderItemsToProcess.push(Promise.resolve({
72
+ unwraps: [],
73
+ confidentialPayments: [payment],
74
+ refunds: [],
75
+ actions: [],
76
+ metadatas: [],
77
+ }));
78
+ return this;
79
+ },
80
+ __refund(refund) {
81
+ this._builderItemsToProcess.push(Promise.resolve({
82
+ unwraps: [],
83
+ confidentialPayments: [],
84
+ refunds: [refund],
85
+ actions: [],
86
+ metadatas: [],
87
+ }));
88
+ return this;
89
+ },
90
+ refundAddr(addr) {
91
+ this._op.refundAddr = addr;
92
+ return this;
93
+ },
94
+ deadline(deadline) {
95
+ this._op.deadline = deadline;
96
+ return this;
97
+ },
98
+ gas(gasParams) {
99
+ const { executionGasLimit, gasPrice } = gasParams;
100
+ this._op.executionGasLimit = executionGasLimit;
101
+ this._op.gasPrice = gasPrice;
102
+ return this;
103
+ },
104
+ gasPrice(gasPrice) {
105
+ this._op.gasPrice = gasPrice;
106
+ return this;
107
+ },
108
+ async build() {
109
+ const metadata = {
110
+ items: [],
111
+ };
112
+ // Await any promises resolving to items to process, then process items
113
+ const netBalanceMap = new core_1.MapWithObjectKeys();
114
+ const unwrapAmountsByAsset = new core_1.MapWithObjectKeys();
115
+ const confPaymentsByAsset = new core_1.MapWithObjectKeys();
116
+ for (const prom of this._builderItemsToProcess) {
117
+ const result = await prom;
118
+ for (const { asset, unwrapValue } of result.unwraps) {
119
+ // Subtract unwrap value from net amount (value being spent from teller)
120
+ netBalanceMap.set(asset, (netBalanceMap.get(asset) ?? 0n) - unwrapValue);
121
+ // If net amount is negative, must add value to unwrap amount to make action possible
122
+ if ((netBalanceMap.get(asset) ?? 0n) < 0n) {
123
+ unwrapAmountsByAsset.set(asset, (unwrapAmountsByAsset.get(asset) ?? 0n) + unwrapValue);
124
+ netBalanceMap.set(asset, 0n); // Reset net back to 0 now that we've added to unwrap amount
125
+ }
126
+ }
127
+ for (const { asset, value, receiver } of result.confidentialPayments) {
128
+ const existingConfPayments = confPaymentsByAsset.get(asset) ?? [];
129
+ confPaymentsByAsset.set(asset, existingConfPayments.concat({ value, receiver }));
130
+ metadata.items.push({
131
+ type: "ConfidentialPayment",
132
+ recipient: receiver,
133
+ asset,
134
+ amount: value,
135
+ });
136
+ }
137
+ for (const { contractAddress, encodedFunction } of result.actions) {
138
+ const action = {
139
+ contractAddress: ethers_1.ethers.utils.getAddress(contractAddress),
140
+ encodedFunction,
141
+ };
142
+ this._op.actions.push(action);
143
+ }
144
+ for (const { asset, minRefundValue } of result.refunds) {
145
+ // Refund value adds funds to net balance (value being received to Handler able to spend
146
+ // in subsequent calls)
147
+ netBalanceMap.set(asset, (netBalanceMap.get(asset) ?? 0n) + minRefundValue);
148
+ }
149
+ for (const metadataItem of result.metadatas) {
150
+ metadata.items.push(metadataItem);
151
+ }
152
+ }
153
+ // Turn unwraps into joinsplit requests and attach payments
154
+ for (const [asset, unwrapAmount] of unwrapAmountsByAsset.entries()) {
155
+ this._op.joinSplitRequests.push({
156
+ asset,
157
+ unwrapValue: unwrapAmount,
158
+ });
159
+ }
160
+ for (const [asset, payments] of confPaymentsByAsset.entries()) {
161
+ for (const payment of payments) {
162
+ const joinSplit = this._op.joinSplitRequests.find((js) => core_1.AssetTrait.isSameAsset(js.asset, asset) &&
163
+ js.payment === undefined);
164
+ if (joinSplit) {
165
+ joinSplit.payment = payment;
166
+ }
167
+ else {
168
+ this._op.joinSplitRequests.push({
169
+ asset,
170
+ unwrapValue: 0n,
171
+ payment,
172
+ });
173
+ }
174
+ }
175
+ }
176
+ // Add refunds for expected outstanding assets
177
+ for (const [asset, netBalance] of netBalanceMap.entries()) {
178
+ if (netBalance > 0n) {
179
+ this._op.refunds.push({
180
+ encodedAsset: core_1.AssetTrait.encode(asset),
181
+ minRefundValue: netBalance,
182
+ });
183
+ }
184
+ }
185
+ return {
186
+ request: this._op,
187
+ meta: metadata,
188
+ };
189
+ },
190
+ };
191
+ }
192
+ //# sourceMappingURL=builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.js","sourceRoot":"","sources":["../../../src/operationRequest/builder.ts"],"names":[],"mappings":";;AAoHA,kDAkPC;AAtWD,kDAG+B;AAW/B,8CAM6B;AAC7B,mCAAgC;AAEhC,kDAA0D;AA2F1D,uFAAuF;AACvF,sHAAsH;AACtH,SAAgB,mBAAmB,CACjC,QAA0C,EAC1C,OAAe,EACf,MAAuB,CAAC,0FAA0F;;IAElH,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,WAAW,GAAG,IAAA,gCAA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itRequest, } from "./operationRequest";
2
+ export { OpRequestBuilder, BaseOpRequestBuilder, OpRequestBuilderExt, OpRequestBuilderPlugin, BuilderItemToProcess, newOpRequestBuilder, } from "./builder";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/operationRequest/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,4BAA4B,EAC5B,aAAa,EACb,aAAa,EACb,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,WAAW,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.newOpRequestBuilder = void 0;
4
+ var builder_1 = require("./builder");
5
+ Object.defineProperty(exports, "newOpRequestBuilder", { enumerable: true, get: function () { return builder_1.newOpRequestBuilder; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/operationRequest/index.ts"],"names":[],"mappings":";;;AAQA,qCAOmB;AADjB,8GAAA,mBAAmB,OAAA"}
@@ -0,0 +1,50 @@
1
+ import { ethers } from "ethers";
2
+ import { CanonAddress, StealthAddress } from "@zill-protocol/crypto";
3
+ import { OperationMetadata } from "../types";
4
+ import { Action, Address, Asset, ExpectedRefund, IncludedNote } from "@zill-protocol/core";
5
+ export interface JoinSplitRequest {
6
+ asset: Asset;
7
+ unwrapValue: bigint;
8
+ payment?: ConfidentialPayment;
9
+ notes?: IncludedNote[];
10
+ allowGasCompensation?: boolean;
11
+ }
12
+ export type UnwrapRequest = Omit<JoinSplitRequest, "payment">;
13
+ export interface RefundRequest extends Omit<ExpectedRefund, "encodedAsset"> {
14
+ asset: Asset;
15
+ }
16
+ export interface ConfidentialPaymentRequest extends ConfidentialPayment {
17
+ asset: Asset;
18
+ }
19
+ export interface OperationRequest {
20
+ joinSplitRequests: JoinSplitRequest[];
21
+ refunds: ExpectedRefund[];
22
+ actions: Action[];
23
+ chainId: bigint;
24
+ tellerContract: Address;
25
+ deadline: bigint;
26
+ refundAddr?: StealthAddress;
27
+ executionGasLimit?: bigint;
28
+ gasPrice?: bigint;
29
+ }
30
+ export interface OperationRequestWithMetadata {
31
+ request: OperationRequest;
32
+ meta: OperationMetadata;
33
+ }
34
+ export interface GasAccountedOperationRequest extends Omit<OperationRequest, "executionGasLimit" | "gasPrice"> {
35
+ gasAssetRefundThreshold: bigint;
36
+ executionGasLimit: bigint;
37
+ gasPrice: bigint;
38
+ gasAsset: Asset;
39
+ totalGasLimit: bigint;
40
+ }
41
+ export interface OperationGasParams {
42
+ executionGasLimit: bigint;
43
+ gasPrice?: bigint;
44
+ }
45
+ export interface ConfidentialPayment {
46
+ value: bigint;
47
+ receiver: CanonAddress;
48
+ }
49
+ export declare function ensureOpRequestChainInfo(opRequest: OperationRequest, provider: ethers.providers.Provider): Promise<OperationRequest>;
50
+ //# sourceMappingURL=operationRequest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operationRequest.d.ts","sourceRoot":"","sources":["../../../src/operationRequest/operationRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EACL,MAAM,EACN,OAAO,EACP,KAAK,EACL,cAAc,EACd,YAAY,EACb,MAAM,qBAAqB,CAAC;AAK7B,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,KAAK,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,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BAAsB,wBAAwB,CAC5C,SAAS,EAAE,gBAAgB,EAC3B,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,GAClC,OAAO,CAAC,gBAAgB,CAAC,CAc3B"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureOpRequestChainInfo = ensureOpRequestChainInfo;
4
+ const ONE_DAY_SECONDS = 24 * 60 * 60;
5
+ async function ensureOpRequestChainInfo(opRequest, provider) {
6
+ if (opRequest.chainId === 0n) {
7
+ const chainId = BigInt((await provider.getNetwork()).chainId);
8
+ opRequest.chainId = chainId;
9
+ }
10
+ if (opRequest.deadline === 0n) {
11
+ const deadline = BigInt((await provider.getBlock("latest")).timestamp + ONE_DAY_SECONDS);
12
+ opRequest.deadline = deadline;
13
+ }
14
+ return opRequest;
15
+ }
16
+ //# sourceMappingURL=operationRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operationRequest.js","sourceRoot":"","sources":["../../../src/operationRequest/operationRequest.ts"],"names":[],"mappings":";;AAqEA,4DAiBC;AA3ED,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AA0D9B,KAAK,UAAU,wBAAwB,CAC5C,SAA2B,EAC3B,QAAmC;IAEnC,IAAI,SAAS,CAAC,OAAO,KAAK,EAAE,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;QAC9D,SAAS,CAAC,OAAO,GAAG,OAAO,CAAC;IAC9B,CAAC;IAED,IAAI,SAAS,CAAC,QAAQ,KAAK,EAAE,EAAE,CAAC;QAC9B,MAAM,QAAQ,GAAG,MAAM,CACrB,CAAC,MAAM,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,GAAG,eAAe,CAChE,CAAC;QACF,SAAS,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAChC,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { NocturneDB } from "./NocturneDB";
2
+ import { GasAccountedOperationRequest } from "./operationRequest/operationRequest";
3
+ import { NocturneViewer } from "@zill-protocol/crypto";
4
+ import { IncludedNote, Asset, PreSignOperation, SparseMerkleProver } from "@zill-protocol/core";
5
+ export declare const __private: {
6
+ gatherNotes: typeof gatherNotes;
7
+ };
8
+ export interface PrepareOperationDeps {
9
+ db: NocturneDB;
10
+ viewer: NocturneViewer;
11
+ merkle: SparseMerkleProver;
12
+ }
13
+ export declare function prepareOperation(deps: PrepareOperationDeps, opRequest: GasAccountedOperationRequest): Promise<PreSignOperation>;
14
+ export declare class NotEnoughFundsError extends Error {
15
+ readonly requestedAmount: bigint;
16
+ readonly ownedAmount: bigint;
17
+ readonly asset: Asset;
18
+ constructor(requestedAmount: bigint, ownedAmount: bigint, asset: Asset);
19
+ }
20
+ export declare function gatherNotes(db: NocturneDB, requestedAmount: bigint, asset: Asset, noteMerkleIndicesToIgnore?: Set<number>): Promise<IncludedNote[]>;
21
+ //# sourceMappingURL=prepareOperation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepareOperation.d.ts","sourceRoot":"","sources":["../../src/prepareOperation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAEL,4BAA4B,EAC7B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,cAAc,EAKf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAIL,YAAY,EACZ,KAAK,EAEL,gBAAgB,EAKhB,kBAAkB,EAInB,MAAM,qBAAqB,CAAC;AAG7B,eAAO,MAAM,SAAS;;CAErB,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,UAAU,CAAC;IACf,MAAM,EAAE,cAAc,CAAC;IACvB,MAAM,EAAE,kBAAkB,CAAC;CAC5B;AAED,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,oBAAoB,EAC1B,SAAS,EAAE,4BAA4B,GACtC,OAAO,CAAC,gBAAgB,CAAC,CAwD3B;AAoDD,qBAAa,mBAAoB,SAAQ,KAAK;aAE1B,eAAe,EAAE,MAAM;aACvB,WAAW,EAAE,MAAM;aACnB,KAAK,EAAE,KAAK;gBAFZ,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,KAAK;CAO/B;AAED,wBAAsB,WAAW,CAC/B,EAAE,EAAE,UAAU,EACd,eAAe,EAAE,MAAM,EACvB,KAAK,EAAE,KAAK,EACZ,yBAAyB,GAAE,GAAG,CAAC,MAAM,CAAa,GACjD,OAAO,CAAC,YAAY,EAAE,CAAC,CA6EzB"}
@@ -0,0 +1,256 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotEnoughFundsError = exports.__private = void 0;
4
+ exports.prepareOperation = prepareOperation;
5
+ exports.gatherNotes = gatherNotes;
6
+ const crypto_1 = require("@zill-protocol/crypto");
7
+ const core_1 = require("@zill-protocol/core");
8
+ const utils_1 = require("./utils");
9
+ exports.__private = {
10
+ gatherNotes,
11
+ };
12
+ async function prepareOperation(deps, opRequest) {
13
+ const { refunds, joinSplitRequests, chainId, tellerContract, deadline } = opRequest;
14
+ const encodedGasAsset = core_1.AssetTrait.encode(opRequest.gasAsset);
15
+ // if refundAddr is not set, generate a random one
16
+ const refundAddr = crypto_1.StealthAddressTrait.compress(opRequest.refundAddr ?? deps.viewer.generateRandomStealthAddress());
17
+ // prepare joinSplits
18
+ let joinSplits = [];
19
+ const usedMerkleIndices = new Set();
20
+ for (const joinSplitRequest of joinSplitRequests) {
21
+ console.log("preparing joinSplits for request: ", joinSplitRequest);
22
+ const newJoinSplits = await prepareJoinSplits(deps, joinSplitRequest, refundAddr, usedMerkleIndices);
23
+ newJoinSplits.forEach((js) => {
24
+ // If note value == 0, its just a dummy and we don't want to count in used merkle indices
25
+ if (js.oldNoteA.value !== 0n) {
26
+ usedMerkleIndices.add(js.oldNoteA.merkleIndex);
27
+ }
28
+ if (js.oldNoteB.value !== 0n) {
29
+ usedMerkleIndices.add(js.oldNoteB.merkleIndex);
30
+ }
31
+ });
32
+ joinSplits.push(...newJoinSplits);
33
+ }
34
+ joinSplits = (0, core_1.groupByArr)(joinSplits, (joinSplit) => core_1.AssetTrait.encodedAssetToString(joinSplit.encodedAsset)).flat();
35
+ // construct op
36
+ const op = {
37
+ networkInfo: { chainId, tellerContract },
38
+ refundAddr,
39
+ joinSplits,
40
+ actions: opRequest.actions,
41
+ refunds,
42
+ encodedGasAsset,
43
+ gasAssetRefundThreshold: opRequest.gasAssetRefundThreshold,
44
+ executionGasLimit: opRequest.executionGasLimit,
45
+ gasPrice: opRequest.gasPrice,
46
+ deadline,
47
+ atomicActions: true, // always default to atomic until we find reason not to
48
+ gasFeeEstimate: opRequest.totalGasLimit * opRequest.gasPrice,
49
+ };
50
+ return op;
51
+ }
52
+ async function prepareJoinSplits({ db, viewer, merkle }, joinSplitRequest, refundAddr, alreadyUsedNoteMerkleIndices = new Set()) {
53
+ let notes;
54
+ if (joinSplitRequest.notes && joinSplitRequest.notes.length > 0) {
55
+ notes = joinSplitRequest.notes;
56
+ const mismatchedAsset = notes.find((note) => !core_1.AssetTrait.isSameAsset(note.asset, joinSplitRequest.asset));
57
+ if (mismatchedAsset) {
58
+ throw new Error("join split request notes asset mismatch");
59
+ }
60
+ const reusedNote = notes.find((note) => alreadyUsedNoteMerkleIndices.has(note.merkleIndex));
61
+ if (reusedNote) {
62
+ throw new Error("join split request notes already used");
63
+ }
64
+ }
65
+ else {
66
+ notes = await gatherNotes(db, (0, utils_1.getJoinSplitRequestTotalValue)(joinSplitRequest), joinSplitRequest.asset, alreadyUsedNoteMerkleIndices);
67
+ }
68
+ const unwrapAmount = joinSplitRequest.unwrapValue;
69
+ const paymentAmount = joinSplitRequest.payment?.value ?? 0n;
70
+ const totalNotesValue = notes.reduce((acc, note) => acc + note.value, 0n);
71
+ const amountToReturn = totalNotesValue - unwrapAmount - paymentAmount;
72
+ const receiver = joinSplitRequest.payment?.receiver;
73
+ console.log(`getting joinsplits from notes. Num notes: ${notes.length}`);
74
+ return getJoinSplitsFromNotes(viewer, merkle, notes, paymentAmount, amountToReturn, refundAddr, receiver);
75
+ }
76
+ class NotEnoughFundsError extends Error {
77
+ constructor(requestedAmount, ownedAmount, asset) {
78
+ super(`attempted to spend more funds than owned. Address: ${asset.assetAddr}. Attempted: ${requestedAmount}. Owned: ${ownedAmount}.`);
79
+ this.requestedAmount = requestedAmount;
80
+ this.ownedAmount = ownedAmount;
81
+ this.asset = asset;
82
+ this.name = "NotEnoughFundsError";
83
+ }
84
+ }
85
+ exports.NotEnoughFundsError = NotEnoughFundsError;
86
+ async function gatherNotes(db, requestedAmount, asset, noteMerkleIndicesToIgnore = new Set()) {
87
+ console.log("indices to ignore", noteMerkleIndicesToIgnore);
88
+ // check that the user has enough notes to cover the request
89
+ const notes = (await db.getNotesForAsset(asset)).filter((n) => !noteMerkleIndicesToIgnore.has(n.merkleIndex));
90
+ const balance = notes.reduce((acc, note) => acc + note.value, 0n);
91
+ if (balance < requestedAmount) {
92
+ // TODO: have a better way to handle following edge case:
93
+ // 1. there are multiple JS requests for the same asset
94
+ // 2. the user has enough notes to cover the total amount
95
+ // 3. the user does *not* have enough to cover each request individually.
96
+ throw new NotEnoughFundsError(requestedAmount, balance, asset);
97
+ }
98
+ // Goal: want to utilize small notes so they don't pile up.
99
+ // But we also don't want to use too many notes because that will increase the gas cost.
100
+ // So we take the following approach that strikes a good balance
101
+ // 1. sort notes from small to large
102
+ // 2. compute the sums of each sequence of notes starting from the smallest.
103
+ // Stop when the sum is >= to the requested amount.
104
+ // 3. until we've gathered notes totalling at least the requested amount, repeat the following:
105
+ // a. find the smallest subsequence sum that is >= to the remaining amount to gather
106
+ // b. add the largest note of that subsequence to the set of notes to use.
107
+ // 4. If this process results in an odd number of notes to spend and there is still room, grab the smallest unused note for dust collection
108
+ // 1. Sort notes from small to large
109
+ const sortedNotes = (0, utils_1.sortNotesByValue)(notes);
110
+ // 2. compute the subsequence sums
111
+ const subsequenceSums = [];
112
+ let curr = 0n;
113
+ for (const note of sortedNotes) {
114
+ curr += note.value;
115
+ subsequenceSums.push(curr);
116
+ }
117
+ // 3. Construct the set of notes to use.
118
+ const notesToUse = [];
119
+ const usedNoteIndexes = new Set();
120
+ let remainingAmount = requestedAmount;
121
+ let subseqIndex = subsequenceSums.length - 1;
122
+ while (remainingAmount > 0n) {
123
+ // find the index of smallest subsequence sum >= remaining amount to gather
124
+ // the note at that index is the next note to add
125
+ while (subseqIndex > 0 &&
126
+ subsequenceSums[subseqIndex - 1] >= remainingAmount) {
127
+ subseqIndex--;
128
+ }
129
+ const note = sortedNotes[subseqIndex];
130
+ notesToUse.push(note);
131
+ remainingAmount -= note.value;
132
+ usedNoteIndexes.add(subseqIndex);
133
+ // Skip to next note
134
+ subseqIndex--;
135
+ }
136
+ // 4. If this process results in an odd number of notes to spend and there is still room, grab the smallest unused note for dust collection
137
+ if (notesToUse.length % 2 == 1 && notesToUse.length < notes.length) {
138
+ const smallestUnusedNote = sortedNotes.find((note, i) => !usedNoteIndexes.has(i));
139
+ if (smallestUnusedNote) {
140
+ notesToUse.push(smallestUnusedNote);
141
+ }
142
+ }
143
+ console.log(`gathered notes to satisfy request for ${requestedAmount} of assest ${asset.assetAddr}`, { notesToUse, requestedAmount, asset });
144
+ return notesToUse;
145
+ }
146
+ async function getJoinSplitsFromNotes(viewer, merkle, notes, paymentAmount, amountLeftOver, refundAddr, receiver) {
147
+ // add a dummy note if there are an odd number of notes.
148
+ if (notes.length % 2 == 1) {
149
+ const newAddr = viewer.generateRandomStealthAddress();
150
+ const nonce = (0, crypto_1.randomFr)();
151
+ notes.push({
152
+ owner: newAddr,
153
+ nonce,
154
+ asset: notes[0].asset,
155
+ value: 0n,
156
+ merkleIndex: 0,
157
+ });
158
+ }
159
+ // for each pair of notes, create a JoinSplit with the maximum possible value transfer
160
+ const res = [];
161
+ let remainingPayment = paymentAmount;
162
+ let remainingAmountLeftOver = amountLeftOver;
163
+ for (const [noteA, noteB] of (0, core_1.iterChunks)(notes, 2)) {
164
+ const pairTotalValue = noteA.value + noteB.value;
165
+ const amountToReturn = (0, core_1.min)(remainingAmountLeftOver, pairTotalValue);
166
+ remainingAmountLeftOver -= amountToReturn;
167
+ const remainingPairValue = pairTotalValue - amountToReturn;
168
+ const paymentAmount = (0, core_1.min)(remainingPairValue, remainingPayment);
169
+ remainingPayment -= paymentAmount;
170
+ const joinSplit = await makeJoinSplit(viewer, merkle, noteA, noteB, paymentAmount, amountToReturn, refundAddr, receiver);
171
+ res.push(joinSplit);
172
+ }
173
+ return res;
174
+ }
175
+ async function makeJoinSplit(viewer, merkle, oldNoteA, oldNoteB, paymentAmount, amountToReturn, refundAddr, receiver) {
176
+ const sender = viewer.canonicalAddress();
177
+ // if receiver not given, assumme the sender is the receiver
178
+ receiver = receiver ?? sender;
179
+ const encodedAsset = core_1.AssetTrait.encode(oldNoteA.asset);
180
+ // whatever isn't being sent to the receiver or ourselves is unwrapped and spent in cleartext (presumably as part of an action)
181
+ const totalValue = oldNoteA.value + oldNoteB.value;
182
+ const publicSpend = totalValue - amountToReturn - paymentAmount;
183
+ const nullifierA = core_1.NoteTrait.createNullifier(viewer, oldNoteA);
184
+ const nullifierB = core_1.NoteTrait.createNullifier(viewer, oldNoteB);
185
+ // first note contains the leftovers - return to sender
186
+ const newNoteA = {
187
+ owner: crypto_1.StealthAddressTrait.fromCanonAddress(sender),
188
+ nonce: core_1.NoteTrait.generateNewNonce(viewer, nullifierA),
189
+ asset: oldNoteA.asset,
190
+ value: amountToReturn,
191
+ };
192
+ // the second note contains the confidential payment
193
+ const newNoteB = {
194
+ owner: crypto_1.StealthAddressTrait.fromCanonAddress(receiver),
195
+ nonce: core_1.NoteTrait.generateNewNonce(viewer, nullifierB),
196
+ asset: oldNoteA.asset,
197
+ value: paymentAmount,
198
+ };
199
+ const newNoteACommitment = core_1.NoteTrait.toCommitment(newNoteA);
200
+ const newNoteBCommitment = core_1.NoteTrait.toCommitment(newNoteB);
201
+ const newNoteAEncrypted = (0, core_1.encryptNote)(sender, { ...newNoteA, sender });
202
+ const newNoteBEncrypted = (0, core_1.encryptNote)(receiver, { ...newNoteB, sender });
203
+ const membershipProof = merkle.getProof(oldNoteA.merkleIndex);
204
+ const commitmentTreeRoot = membershipProof.root;
205
+ const merkleProofA = {
206
+ path: membershipProof.pathIndices.map((n) => BigInt(n)),
207
+ siblings: membershipProof.siblings,
208
+ };
209
+ // noteB could have been a dummy note. If it is, we simply duplicate the merkle proof for noteA
210
+ // the circuit will ignore the merkle proof for noteB if it has a value of 0
211
+ const noteBIsDummy = oldNoteB.value === 0n;
212
+ let merkleProofB;
213
+ if (noteBIsDummy) {
214
+ oldNoteB.merkleIndex = oldNoteA.merkleIndex;
215
+ merkleProofB = merkleProofA;
216
+ }
217
+ else {
218
+ const membershipProof = merkle.getProof(oldNoteB.merkleIndex);
219
+ // ! merkle tree could be asynchronously updated between us getting the first and second merkle proofs
220
+ // TODO: add a `merkle.getManyProofs` method that does it in one go
221
+ if (membershipProof.root !== commitmentTreeRoot) {
222
+ throw Error("merkleProver was updated between getting the first and second merkle proofs!");
223
+ }
224
+ merkleProofB = {
225
+ path: membershipProof.pathIndices.map((n) => BigInt(n)),
226
+ siblings: membershipProof.siblings,
227
+ };
228
+ }
229
+ // commit to the sender's canonical address
230
+ const senderCanonAddr = viewer.canonicalAddress();
231
+ const senderCommitment = (0, core_1.computeSenderCommitment)(senderCanonAddr, newNoteB.nonce);
232
+ // compute joinsplit info commitment
233
+ const joinSplitInfoCommitment = (0, core_1.computeJoinSplitInfoCommitment)(viewer, receiver, oldNoteA, oldNoteB, newNoteA, newNoteB);
234
+ return {
235
+ receiver,
236
+ encodedAsset,
237
+ publicSpend,
238
+ nullifierA,
239
+ nullifierB,
240
+ oldNoteA,
241
+ oldNoteB,
242
+ newNoteA,
243
+ newNoteB,
244
+ newNoteAEncrypted,
245
+ newNoteBEncrypted,
246
+ commitmentTreeRoot,
247
+ newNoteACommitment,
248
+ newNoteBCommitment,
249
+ merkleProofA,
250
+ merkleProofB,
251
+ senderCommitment,
252
+ joinSplitInfoCommitment,
253
+ refundAddr,
254
+ };
255
+ }
256
+ //# sourceMappingURL=prepareOperation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepareOperation.js","sourceRoot":"","sources":["../../src/prepareOperation.ts"],"names":[],"mappings":";;;AAyCA,4CA2DC;AAiED,kCAkFC;AAlPD,kDAM+B;AAC/B,8CAgB6B;AAC7B,mCAA0E;AAE7D,QAAA,SAAS,GAAG;IACvB,WAAW;CACZ,CAAC;AAQK,KAAK,UAAU,gBAAgB,CACpC,IAA0B,EAC1B,SAAuC;IAEvC,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,GACrE,SAAS,CAAC;IACZ,MAAM,eAAe,GAAG,iBAAU,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAE9D,kDAAkD;IAClD,MAAM,UAAU,GAAG,4BAAmB,CAAC,QAAQ,CAC7C,SAAS,CAAC,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,4BAA4B,EAAE,CACnE,CAAC;IAEF,qBAAqB;IACrB,IAAI,UAAU,GAAuB,EAAE,CAAC;IACxC,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAU,CAAC;IAC5C,KAAK,MAAM,gBAAgB,IAAI,iBAAiB,EAAE,CAAC;QACjD,OAAO,CAAC,GAAG,CAAC,oCAAoC,EAAE,gBAAgB,CAAC,CAAC;QACpE,MAAM,aAAa,GAAG,MAAM,iBAAiB,CAC3C,IAAI,EACJ,gBAAgB,EAChB,UAAU,EACV,iBAAiB,CAClB,CAAC;QAEF,aAAa,CAAC,OAAO,CAAC,CAAC,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CAAC,WAAW,CAAC;QAC5C,YAAY,GAAG,YAAY,CAAC;IAC9B,CAAC;SAAM,CAAC;QACN,MAAM,eAAe,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QAE9D,sGAAsG;QACtG,mEAAmE;QACnE,IAAI,eAAe,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;YAChD,MAAM,KAAK,CACT,8EAA8E,CAC/E,CAAC;QACJ,CAAC;QAED,YAAY,GAAG;YACb,IAAI,EAAE,eAAe,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACvD,QAAQ,EAAE,eAAe,CAAC,QAAQ;SACnC,CAAC;IACJ,CAAC;IAED,2CAA2C;IAC3C,MAAM,eAAe,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;IAClD,MAAM,gBAAgB,GAAG,IAAA,8BAAuB,EAC9C,eAAe,EACf,QAAQ,CAAC,KAAK,CACf,CAAC;IAEF,oCAAoC;IACpC,MAAM,uBAAuB,GAAG,IAAA,qCAA8B,EAC5D,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,CACT,CAAC;IAEF,OAAO;QACL,QAAQ;QACR,YAAY;QACZ,WAAW;QAEX,UAAU;QACV,UAAU;QACV,QAAQ;QACR,QAAQ;QAER,QAAQ;QACR,QAAQ;QACR,iBAAiB;QACjB,iBAAiB;QAEjB,kBAAkB;QAClB,kBAAkB;QAClB,kBAAkB;QAClB,YAAY;QACZ,YAAY;QAEZ,gBAAgB;QAChB,uBAAuB;QACvB,UAAU;KACX,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { SignedOperation, SubmittableOperationWithNetworkInfo, JoinSplitProver } from "@zill-protocol/core";
2
+ export type ProveOperationOptions = {
3
+ maxParallel?: number;
4
+ debug?: boolean;
5
+ };
6
+ export declare function proveOperation(prover: JoinSplitProver, op: SignedOperation, opts?: ProveOperationOptions): Promise<SubmittableOperationWithNetworkInfo>;
7
+ //# sourceMappingURL=proveOperation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proveOperation.d.ts","sourceRoot":"","sources":["../../src/proveOperation.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,eAAe,EAIf,mCAAmC,EACnC,eAAe,EAIhB,MAAM,qBAAqB,CAAC;AAK7B,MAAM,MAAM,qBAAqB,GAAG;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,wBAAsB,cAAc,CAClC,MAAM,EAAE,eAAe,EACvB,EAAE,EAAE,eAAe,EACnB,IAAI,CAAC,EAAE,qBAAqB,GAC3B,OAAO,CAAC,mCAAmC,CAAC,CAgB9C"}