ecash-agora 0.3.2 → 0.4.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/README.md CHANGED
@@ -174,3 +174,7 @@ Running from `bitcoin-abc/modules/ecash-agora` if your build dir is `bitcoin-abc
174
174
  ### 0.3.2
175
175
 
176
176
  - Improve offer checks in `historicOffers` [D17630](https://reviews.bitcoinabc.org/D17630)
177
+
178
+ ### 0.4.0
179
+
180
+ - Add `getAgoraPartialAcceptFuelInputs` and `getAgoraCancelFuelInputs` [D17637](https://reviews.bitcoinabc.org/D17637)
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './ad.js';
2
2
  export * from './agora.js';
3
3
  export * from './consts.js';
4
+ export * from './inputs.js';
4
5
  export * from './oneshot.js';
5
6
  export * from './partial.js';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
20
20
  __exportStar(require("./ad.js"), exports);
21
21
  __exportStar(require("./agora.js"), exports);
22
22
  __exportStar(require("./consts.js"), exports);
23
+ __exportStar(require("./inputs.js"), exports);
23
24
  __exportStar(require("./oneshot.js"), exports);
24
25
  __exportStar(require("./partial.js"), exports);
25
26
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,mEAAmE;AACnE,sEAAsE;;;;;;;;;;;;;;;;AAEtE,0CAAwB;AACxB,6CAA2B;AAC3B,8CAA4B;AAC5B,+CAA6B;AAC7B,+CAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,mEAAmE;AACnE,sEAAsE;;;;;;;;;;;;;;;;AAEtE,0CAAwB;AACxB,6CAA2B;AAC3B,8CAA4B;AAC5B,8CAA4B;AAC5B,+CAA6B;AAC7B,+CAA6B"}
@@ -0,0 +1,22 @@
1
+ import { ScriptUtxo } from 'chronik-client';
2
+ import { AgoraOffer } from './agora';
3
+ export declare const DUMMY_KEYPAIR: {
4
+ sk: Uint8Array;
5
+ pk: Uint8Array;
6
+ };
7
+ /**
8
+ * Determine input utxos to cover an Agora Partial accept offer
9
+ */
10
+ export declare const getAgoraPartialAcceptFuelInputs: (agoraOffer: AgoraOffer, utxos: ScriptUtxo[], acceptedTokens: bigint, feePerKb?: number) => ScriptUtxo[];
11
+ /**
12
+ * Determine input utxos to cover an Agora ONESHOT accept offer
13
+ * Note: we could refactor getAgoraPartialAcceptFuelInputs to work with ONESHOT offers
14
+ * However there is some ambiguity involved with the acceptedTokens param
15
+ * Cleaner to keep distinct functions
16
+ */
17
+ export declare const getAgoraOneshotAcceptFuelInputs: (agoraOffer: AgoraOffer, utxos: ScriptUtxo[], feePerKb?: number) => ScriptUtxo[];
18
+ /**
19
+ * Determine input utxos to cancel an Agora offer (Partial or ONESHOT)
20
+ */
21
+ export declare const getAgoraCancelFuelInputs: (agoraOffer: AgoraOffer, utxos: ScriptUtxo[], feePerKb?: number) => ScriptUtxo[];
22
+ //# sourceMappingURL=inputs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../src/inputs.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAOrC,eAAO,MAAM,aAAa;;;CAKzB,CAAC;AAiBF;;GAEG;AACH,eAAO,MAAM,+BAA+B,eAC5B,UAAU,SACf,UAAU,EAAE,kBACH,MAAM,wBAEvB,UAAU,EA6BZ,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B,eAC5B,UAAU,SACf,UAAU,EAAE,wBAEpB,UAAU,EA4BZ,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,eACrB,UAAU,SACf,UAAU,EAAE,wBAEpB,UAAU,EA2BZ,CAAC"}
package/dist/inputs.js ADDED
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ // Copyright (c) 2025 The Bitcoin developers
3
+ // Distributed under the MIT software license, see the accompanying
4
+ // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getAgoraCancelFuelInputs = exports.getAgoraOneshotAcceptFuelInputs = exports.getAgoraPartialAcceptFuelInputs = exports.DUMMY_KEYPAIR = void 0;
7
+ const ecash_lib_1 = require("ecash-lib");
8
+ const DUMMY_TXID = '1111111111111111111111111111111111111111111111111111111111111111';
9
+ const DUMMY_WALLET_HASH = (0, ecash_lib_1.fromHex)('12'.repeat(20));
10
+ const DUMMY_SUFFICIENT_CANCEL_VALUE = 10000;
11
+ const DUMMY_SCRIPT = ecash_lib_1.Script.p2pkh(DUMMY_WALLET_HASH);
12
+ exports.DUMMY_KEYPAIR = {
13
+ sk: (0, ecash_lib_1.fromHex)('33'.repeat(32)),
14
+ pk: (0, ecash_lib_1.fromHex)('023c72addb4fdf09af94f0c94d7fe92a386a7e70cf8a1d85916386bb2535c7b1b1'),
15
+ };
16
+ // Used for accept and cancel fee estimation of agora partial offers
17
+ const DUMMY_INPUT = {
18
+ input: {
19
+ prevOut: {
20
+ txid: DUMMY_TXID,
21
+ outIdx: 1,
22
+ },
23
+ signData: {
24
+ value: DUMMY_SUFFICIENT_CANCEL_VALUE,
25
+ outputScript: DUMMY_SCRIPT,
26
+ },
27
+ },
28
+ signatory: (0, ecash_lib_1.P2PKHSignatory)(exports.DUMMY_KEYPAIR.sk, exports.DUMMY_KEYPAIR.pk, ecash_lib_1.ALL_BIP143),
29
+ };
30
+ /**
31
+ * Determine input utxos to cover an Agora Partial accept offer
32
+ */
33
+ const getAgoraPartialAcceptFuelInputs = (agoraOffer, utxos, acceptedTokens, feePerKb = ecash_lib_1.DEFAULT_FEE_PER_KB) => {
34
+ const fuelInputs = [];
35
+ const dummyInputs = [];
36
+ let inputSatoshis = 0n;
37
+ for (const utxo of utxos) {
38
+ // Accumulative utxo selection
39
+ fuelInputs.push(utxo);
40
+ // Match our fuelInput count with dummyInputs
41
+ dummyInputs.push(DUMMY_INPUT);
42
+ inputSatoshis += BigInt(utxo.value);
43
+ const askedSats = agoraOffer.askedSats(BigInt(acceptedTokens));
44
+ // Get the tx fee for this tx
45
+ const acceptFeeSats = agoraOffer.acceptFeeSats({
46
+ recipientScript: DUMMY_SCRIPT,
47
+ extraInputs: dummyInputs,
48
+ acceptedTokens,
49
+ feePerKb,
50
+ });
51
+ // We need to cover the tx fee and the asking price
52
+ const requiredSats = acceptFeeSats + askedSats;
53
+ if (inputSatoshis >= requiredSats) {
54
+ return fuelInputs;
55
+ }
56
+ }
57
+ throw new Error('Insufficient utxos to accept this offer');
58
+ };
59
+ exports.getAgoraPartialAcceptFuelInputs = getAgoraPartialAcceptFuelInputs;
60
+ /**
61
+ * Determine input utxos to cover an Agora ONESHOT accept offer
62
+ * Note: we could refactor getAgoraPartialAcceptFuelInputs to work with ONESHOT offers
63
+ * However there is some ambiguity involved with the acceptedTokens param
64
+ * Cleaner to keep distinct functions
65
+ */
66
+ const getAgoraOneshotAcceptFuelInputs = (agoraOffer, utxos, feePerKb = ecash_lib_1.DEFAULT_FEE_PER_KB) => {
67
+ const fuelInputs = [];
68
+ const dummyInputs = [];
69
+ let inputSatoshis = 0n;
70
+ for (const utxo of utxos) {
71
+ // Accumulative utxo selection
72
+ fuelInputs.push(utxo);
73
+ // Match our fuelInput count with dummyInputs
74
+ dummyInputs.push(DUMMY_INPUT);
75
+ inputSatoshis += BigInt(utxo.value);
76
+ const askedSats = agoraOffer.askedSats();
77
+ // Get the tx fee for this tx
78
+ const acceptFeeSats = agoraOffer.acceptFeeSats({
79
+ recipientScript: DUMMY_SCRIPT,
80
+ extraInputs: dummyInputs,
81
+ feePerKb,
82
+ });
83
+ // We need to cover the tx fee and the asking price
84
+ const requiredSats = acceptFeeSats + askedSats;
85
+ if (inputSatoshis >= requiredSats) {
86
+ return fuelInputs;
87
+ }
88
+ }
89
+ throw new Error('Insufficient utxos to accept this offer');
90
+ };
91
+ exports.getAgoraOneshotAcceptFuelInputs = getAgoraOneshotAcceptFuelInputs;
92
+ /**
93
+ * Determine input utxos to cancel an Agora offer (Partial or ONESHOT)
94
+ */
95
+ const getAgoraCancelFuelInputs = (agoraOffer, utxos, feePerKb = ecash_lib_1.DEFAULT_FEE_PER_KB) => {
96
+ const fuelInputs = [];
97
+ const dummyInputs = [];
98
+ let inputSatoshis = 0n;
99
+ for (const utxo of utxos) {
100
+ // Accumulative utxo selection
101
+ fuelInputs.push(utxo);
102
+ // Match our fuelInput count with dummyInputs
103
+ dummyInputs.push(DUMMY_INPUT);
104
+ inputSatoshis += BigInt(utxo.value);
105
+ // Get the tx fee for this tx
106
+ // In practice, this is always bigger than dust
107
+ // So we do not check to make sure the output we cover is at least dust
108
+ const cancelFeeSats = agoraOffer.cancelFeeSats({
109
+ recipientScript: DUMMY_SCRIPT,
110
+ extraInputs: dummyInputs,
111
+ feePerKb,
112
+ });
113
+ // There is no asking price for cancellation
114
+ // cancelFeeSats is the size of the output we need
115
+ if (inputSatoshis >= cancelFeeSats) {
116
+ return fuelInputs;
117
+ }
118
+ }
119
+ throw new Error('Insufficient utxos to cancel this offer');
120
+ };
121
+ exports.getAgoraCancelFuelInputs = getAgoraCancelFuelInputs;
122
+ //# sourceMappingURL=inputs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inputs.js","sourceRoot":"","sources":["../src/inputs.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,mEAAmE;AACnE,sEAAsE;;;AAEtE,yCAMmB;AAKnB,MAAM,UAAU,GACZ,kEAAkE,CAAC;AACvE,MAAM,iBAAiB,GAAG,IAAA,mBAAO,EAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;AACnD,MAAM,6BAA6B,GAAG,KAAK,CAAC;AAC5C,MAAM,YAAY,GAAG,kBAAM,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;AACxC,QAAA,aAAa,GAAG;IACzB,EAAE,EAAE,IAAA,mBAAO,EAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC5B,EAAE,EAAE,IAAA,mBAAO,EACP,oEAAoE,CACvE;CACJ,CAAC;AAEF,oEAAoE;AACpE,MAAM,WAAW,GAAG;IAChB,KAAK,EAAE;QACH,OAAO,EAAE;YACL,IAAI,EAAE,UAAU;YAChB,MAAM,EAAE,CAAC;SACZ;QACD,QAAQ,EAAE;YACN,KAAK,EAAE,6BAA6B;YACpC,YAAY,EAAE,YAAY;SAC7B;KACJ;IACD,SAAS,EAAE,IAAA,0BAAc,EAAC,qBAAa,CAAC,EAAE,EAAE,qBAAa,CAAC,EAAE,EAAE,sBAAU,CAAC;CAC5E,CAAC;AAEF;;GAEG;AACI,MAAM,+BAA+B,GAAG,CAC3C,UAAsB,EACtB,KAAmB,EACnB,cAAsB,EACtB,QAAQ,GAAG,8BAAkB,EACjB,EAAE;IACd,MAAM,UAAU,GAAG,EAAE,CAAC;IACtB,MAAM,WAAW,GAAG,EAAE,CAAC;IACvB,IAAI,aAAa,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AAC;AA/BW,QAAA,wBAAwB,4BA+BnC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ecash-agora",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "Library for interacting with the eCash Agora protocol",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {