@chainvue/verus-sdk 0.9.0 → 0.11.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 +6 -0
- package/dist/VerusSDK.d.ts +28 -0
- package/dist/VerusSDK.d.ts.map +1 -1
- package/dist/VerusSDK.js +47 -0
- package/dist/VerusSDK.js.map +1 -1
- package/dist/assemble/assembler.d.ts +66 -0
- package/dist/assemble/assembler.d.ts.map +1 -0
- package/dist/assemble/assembler.js +155 -0
- package/dist/assemble/assembler.js.map +1 -0
- package/dist/assemble/fundedIdentityUpdate.d.ts +35 -0
- package/dist/assemble/fundedIdentityUpdate.d.ts.map +1 -0
- package/dist/assemble/fundedIdentityUpdate.js +114 -0
- package/dist/assemble/fundedIdentityUpdate.js.map +1 -0
- package/dist/bundle.js +29599 -29208
- package/dist/currency/index.d.ts.map +1 -1
- package/dist/currency/index.js +32 -66
- package/dist/currency/index.js.map +1 -1
- package/dist/fork/boundary.d.ts +19 -0
- package/dist/fork/boundary.d.ts.map +1 -0
- package/dist/fork/boundary.js +54 -0
- package/dist/fork/boundary.js.map +1 -0
- package/dist/fork-shims.d.ts +7 -0
- package/dist/identity/index.d.ts +12 -2
- package/dist/identity/index.d.ts.map +1 -1
- package/dist/identity/index.js +211 -296
- package/dist/identity/index.js.map +1 -1
- package/dist/identity/public.d.ts +21 -0
- package/dist/identity/public.d.ts.map +1 -0
- package/dist/identity/public.js +38 -0
- package/dist/identity/public.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/message/index.js +7 -7
- package/dist/message/index.js.map +1 -1
- package/dist/offers/identity.d.ts +193 -0
- package/dist/offers/identity.d.ts.map +1 -0
- package/dist/offers/identity.js +314 -0
- package/dist/offers/identity.js.map +1 -0
- package/dist/offers/maker.d.ts +67 -0
- package/dist/offers/maker.d.ts.map +1 -0
- package/dist/offers/maker.js +132 -0
- package/dist/offers/maker.js.map +1 -0
- package/dist/offers/public.d.ts +30 -0
- package/dist/offers/public.d.ts.map +1 -0
- package/dist/offers/public.js +42 -0
- package/dist/offers/public.js.map +1 -0
- package/dist/offers/sign.d.ts +42 -0
- package/dist/offers/sign.d.ts.map +1 -0
- package/dist/offers/sign.js +98 -0
- package/dist/offers/sign.js.map +1 -0
- package/dist/offers/taker.d.ts +33 -0
- package/dist/offers/taker.d.ts.map +1 -0
- package/dist/offers/taker.js +113 -0
- package/dist/offers/taker.js.map +1 -0
- package/dist/signing/index.d.ts +1 -1
- package/dist/signing/index.d.ts.map +1 -1
- package/dist/signing/index.js +10 -10
- package/dist/signing/index.js.map +1 -1
- package/dist/transfer/index.d.ts.map +1 -1
- package/dist/transfer/index.js +40 -62
- package/dist/transfer/index.js.map +1 -1
- package/dist/types/index.d.ts +0 -47
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +6 -11
- package/dist/utils/index.js.map +1 -1
- package/dist/utxo/index.d.ts +7 -0
- package/dist/utxo/index.d.ts.map +1 -1
- package/dist/utxo/index.js +5 -4
- package/dist/utxo/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildSellIdentityOffer = buildSellIdentityOffer;
|
|
4
|
+
exports.completeSellIdentityOffer = completeSellIdentityOffer;
|
|
5
|
+
exports.buildBuyIdentityOffer = buildBuyIdentityOffer;
|
|
6
|
+
exports.completeBuyIdentityOffer = completeBuyIdentityOffer;
|
|
7
|
+
exports.buildSwapIdentityOffer = buildSwapIdentityOffer;
|
|
8
|
+
exports.completeSwapIdentityOffer = completeSwapIdentityOffer;
|
|
9
|
+
/**
|
|
10
|
+
* Marketplace offers that trade a VerusID, offline (currency ↔ identity).
|
|
11
|
+
*
|
|
12
|
+
* An identity is offered by spending its current on-chain primary output (an
|
|
13
|
+
* EVAL_IDENTITY_PRIMARY CC) — there is no separate funding transaction, unlike a
|
|
14
|
+
* currency offer. The maker signs that identity input with
|
|
15
|
+
* SIGHASH_SINGLE|ANYONECANPAY (0x83) committing to a single wanted output (the
|
|
16
|
+
* currency paid to the maker); the taker completes the swap by appending the
|
|
17
|
+
* TRANSFERRED identity output — the same identity with its primary addresses
|
|
18
|
+
* replaced by the taker's — plus the payment for the wanted currency.
|
|
19
|
+
*
|
|
20
|
+
* The transferred identity output is built byte-identically to the daemon's
|
|
21
|
+
* `takeoffer`: `Identity.fromJson(getidentity)` with `setPrimaryAddresses`, then
|
|
22
|
+
* `buildIdentityScript` (verified on VRSCTEST).
|
|
23
|
+
*
|
|
24
|
+
* All three flows are covered and live-proven on VRSCTEST:
|
|
25
|
+
* - SELL (offer the identity, want a currency): the maker spends the identity's
|
|
26
|
+
* current primary output with 0x83; the taker appends the transferred identity
|
|
27
|
+
* and pays. No funding tx.
|
|
28
|
+
* - BUY (offer a currency, want an identity): the maker funds the currency into a
|
|
29
|
+
* commitment and offers it, wanting the identity transferred to the buyer; the
|
|
30
|
+
* taker (the identity's owner) spends the identity's current output and takes
|
|
31
|
+
* the currency.
|
|
32
|
+
* - SWAP (offer an identity, want an identity): the maker spends the offered
|
|
33
|
+
* identity's output with 0x83, wanting the other identity transferred to them;
|
|
34
|
+
* the taker (who owns the wanted identity) spends its output and receives the
|
|
35
|
+
* offered identity. No currency moves — the taker funds only the miner fee.
|
|
36
|
+
*/
|
|
37
|
+
const boundary_js_1 = require("../fork/boundary.js");
|
|
38
|
+
const index_js_1 = require("../utxo/index.js");
|
|
39
|
+
const index_js_2 = require("../signing/index.js");
|
|
40
|
+
const index_js_3 = require("../identity/index.js");
|
|
41
|
+
const sign_js_1 = require("./sign.js");
|
|
42
|
+
const maker_js_1 = require("./maker.js");
|
|
43
|
+
const index_js_4 = require("../utils/index.js");
|
|
44
|
+
const brands_js_1 = require("../core/brands.js");
|
|
45
|
+
const index_js_5 = require("../constants/index.js");
|
|
46
|
+
const errors_js_1 = require("../errors.js");
|
|
47
|
+
/** A native payment script to an R-address (P2PKH) or i-address (pay-to-identity). */
|
|
48
|
+
function nativePaymentScript(address) {
|
|
49
|
+
return address.startsWith('i')
|
|
50
|
+
? (0, index_js_3.identityPaymentScript)((0, brands_js_1.parseIAddress)(address, 'address'))
|
|
51
|
+
: (0, index_js_4.addressToScriptPubKey)(address);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Build the TRANSFERRED identity output: the given identity with its primary
|
|
55
|
+
* addresses replaced by `newPrimaryAddresses`, everything else preserved. Built
|
|
56
|
+
* byte-identically to the daemon's makeoffer/takeoffer identity transfer.
|
|
57
|
+
*/
|
|
58
|
+
function buildTransferredIdentity(identityJson, newPrimaryAddresses) {
|
|
59
|
+
const identity = boundary_js_1.Identity.fromJson(identityJson);
|
|
60
|
+
identity.setPrimaryAddresses(newPrimaryAddresses);
|
|
61
|
+
return (0, index_js_3.buildIdentityScript)(identity);
|
|
62
|
+
}
|
|
63
|
+
/** An offer MUST expire at a real future height; the daemon rejects 0 as expired. */
|
|
64
|
+
function assertExpiryHeight(expiryHeight) {
|
|
65
|
+
if (!Number.isInteger(expiryHeight) || expiryHeight <= 0) {
|
|
66
|
+
throw new errors_js_1.TransactionBuildError('expiryHeight (a positive future block height) is required for an offer; the daemon rejects a 0/never-expiring offer as expired.');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Fund the miner fee for an identity-offer taker (buy / swap) and sign their side.
|
|
71
|
+
*
|
|
72
|
+
* Both completions spend an identity input (0 native) already added by the caller,
|
|
73
|
+
* plus native UTXOs for the fee only. The fee UTXOs must be the NATIVE coin
|
|
74
|
+
* (P2PKH) controlled by `wif`, and this is enforced fail-closed:
|
|
75
|
+
* - a token-bearing (reserve) UTXO is rejected — this flow builds no reserve
|
|
76
|
+
* change output, so its token value would be silently dropped; and
|
|
77
|
+
* - a native UTXO whose scriptPubKey doesn't match `wif`'s address is rejected —
|
|
78
|
+
* it would otherwise produce a signature the daemon only rejects at broadcast.
|
|
79
|
+
*
|
|
80
|
+
* `extraInputNative` is the native carried by the maker's committed input (the
|
|
81
|
+
* offered amount for a native buy offer, else 0).
|
|
82
|
+
*/
|
|
83
|
+
function fundFeeAndSignIdentityTaker(args) {
|
|
84
|
+
const systemId = index_js_5.NETWORK_CONFIG[args.network].chainId;
|
|
85
|
+
const verusNetwork = (0, index_js_2.getNetwork)(args.network === 'testnet');
|
|
86
|
+
const selection = (0, index_js_1.selectUtxos)(args.takerUtxos, 0n, new Map(), 3, systemId, undefined, true, args.extraOutputBytes);
|
|
87
|
+
// Fee UTXOs must carry only the native coin: no reserve change output is built
|
|
88
|
+
// here, so a selected token-bearing UTXO would lose its reserve value.
|
|
89
|
+
if (selection.currencyChanges.size > 0) {
|
|
90
|
+
throw new errors_js_1.TransactionBuildError(`${args.label}: the fee UTXOs must carry only the native coin; a token-bearing UTXO was selected and its reserve value would be lost.`);
|
|
91
|
+
}
|
|
92
|
+
// Every native fee input must be P2PKH controlled by `wif` (CC inputs — the
|
|
93
|
+
// identity — are added by the caller and signed by the key that controls them).
|
|
94
|
+
const expectedScript = (0, index_js_4.addressToScriptPubKey)(boundary_js_1.ECPair.fromWIF(args.wif, verusNetwork).getAddress()).toString('hex');
|
|
95
|
+
const takerInputs = [...args.priorInputs];
|
|
96
|
+
for (const u of selection.selected) {
|
|
97
|
+
if (!(0, index_js_1.isSmartTransactionScript)(Buffer.from(u.script, 'hex')) && u.script !== expectedScript) {
|
|
98
|
+
throw new errors_js_1.TransactionBuildError(`${args.label}: fee UTXO ${u.txid}:${u.outputIndex} is not controlled by the provided wif (its scriptPubKey does not match the wif's address).`);
|
|
99
|
+
}
|
|
100
|
+
const idx = args.tx.addInput(Buffer.from(u.txid, 'hex').reverse(), u.outputIndex, 0xffffffff);
|
|
101
|
+
takerInputs.push({ index: idx, prevOutScript: Buffer.from(u.script, 'hex'), value: u.satoshis });
|
|
102
|
+
}
|
|
103
|
+
// Native change, if any (no currency moves through the fee inputs).
|
|
104
|
+
if (selection.nativeChange > 0n) {
|
|
105
|
+
args.tx.addOutput(nativePaymentScript(args.changeAddress), (0, index_js_4.toSafeNumber)(selection.nativeChange));
|
|
106
|
+
}
|
|
107
|
+
const feeNativeIn = selection.selected.reduce((s, u) => s + u.satoshis, 0n);
|
|
108
|
+
(0, index_js_2.assertNativeConservation)([{ satoshis: args.extraInputNative + feeNativeIn }], args.tx.outs, selection.fee, args.label);
|
|
109
|
+
const { signedTx, txid } = (0, sign_js_1.signTakerInputs)(args.tx.toHex(), takerInputs, args.wif, args.network);
|
|
110
|
+
return { swapTx: signedTx, txid };
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Build the maker's half of a sell-identity offer: spend the identity's current
|
|
114
|
+
* primary output with 0x83 into the single wanted-currency output. This is
|
|
115
|
+
* exactly a `buildOffer` whose "commitment" is the identity output (0 native).
|
|
116
|
+
*/
|
|
117
|
+
function buildSellIdentityOffer(params, network) {
|
|
118
|
+
const commitment = {
|
|
119
|
+
txid: params.identityOutput.txid,
|
|
120
|
+
vout: params.identityOutput.vout,
|
|
121
|
+
value: 0n, // an identity primary output carries 0 native
|
|
122
|
+
script: params.identityOutput.script,
|
|
123
|
+
};
|
|
124
|
+
return (0, maker_js_1.buildOffer)({ wif: params.wif, commitment, want: params.want, expiryHeight: params.expiryHeight }, network);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Complete a sell-identity offer: pay the wanted currency, receive the identity
|
|
128
|
+
* (transferred to `newPrimaryAddresses`), and sign the taker's side.
|
|
129
|
+
*/
|
|
130
|
+
function completeSellIdentityOffer(params, network) {
|
|
131
|
+
const verusNetwork = (0, index_js_2.getNetwork)(network === 'testnet');
|
|
132
|
+
const systemId = index_js_5.NETWORK_CONFIG[network].chainId;
|
|
133
|
+
const wantingNative = params.want.currency === systemId;
|
|
134
|
+
if (params.want.amount <= 0n) {
|
|
135
|
+
throw new errors_js_1.TransactionBuildError('completeSellIdentityOffer: want.amount must be positive');
|
|
136
|
+
}
|
|
137
|
+
if (params.newPrimaryAddresses.length === 0) {
|
|
138
|
+
throw new errors_js_1.TransactionBuildError('completeSellIdentityOffer: newPrimaryAddresses must not be empty');
|
|
139
|
+
}
|
|
140
|
+
const tx = boundary_js_1.Transaction.fromHex(params.offerTx, verusNetwork);
|
|
141
|
+
if (tx.ins.length !== 1 || tx.outs.length !== 1) {
|
|
142
|
+
throw new errors_js_1.TransactionBuildError('completeSellIdentityOffer: expected a maker offer partial (1 input, 1 output)');
|
|
143
|
+
}
|
|
144
|
+
// Output 1: the TRANSFERRED identity — the same identity with its primary
|
|
145
|
+
// addresses replaced by the taker's. Everything else (revocation/recovery,
|
|
146
|
+
// name, parent, contentmap, flags) is preserved, byte-identical to the daemon.
|
|
147
|
+
tx.addOutput(buildTransferredIdentity(params.identityJson, params.newPrimaryAddresses), 0);
|
|
148
|
+
// The taker's own UTXOs fund the wanted currency (paid to output 0) + the fee.
|
|
149
|
+
const wantedTokenReq = wantingNative
|
|
150
|
+
? new Map()
|
|
151
|
+
: new Map([[params.want.currency, params.want.amount]]);
|
|
152
|
+
const requiredNative = wantingNative ? params.want.amount : 0n;
|
|
153
|
+
const selection = (0, index_js_1.selectUtxos)(params.takerUtxos, requiredNative, wantedTokenReq, 3, systemId, undefined, true, 150);
|
|
154
|
+
const takerInputs = [];
|
|
155
|
+
for (const u of selection.selected) {
|
|
156
|
+
const idx = tx.addInput(Buffer.from(u.txid, 'hex').reverse(), u.outputIndex, 0xffffffff);
|
|
157
|
+
takerInputs.push({ index: idx, prevOutScript: Buffer.from(u.script, 'hex'), value: u.satoshis });
|
|
158
|
+
}
|
|
159
|
+
// Output 2: taker change (bundled token+native reserve output, or plain native).
|
|
160
|
+
const hasTokenChange = selection.currencyChanges.size > 0;
|
|
161
|
+
if (hasTokenChange || selection.nativeChange > 0n) {
|
|
162
|
+
if (hasTokenChange) {
|
|
163
|
+
const change = (0, index_js_3.buildTokenChangeOutput)((0, brands_js_1.parseAddress)(params.changeAddress, 'changeAddress'), selection.currencyChanges);
|
|
164
|
+
tx.addOutput(change.script, (0, index_js_4.toSafeNumber)(selection.nativeChange));
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
tx.addOutput(nativePaymentScript(params.changeAddress), (0, index_js_4.toSafeNumber)(selection.nativeChange));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// Token conservation over the taker's own inputs (wanted token → output 0 + change).
|
|
171
|
+
(0, index_js_1.assertTokenConservation)(selection.selected, wantedTokenReq, selection.currencyChanges, systemId, 'takeSellIdentityOffer');
|
|
172
|
+
// Native conservation: the identity input carries 0 native, so the taker's
|
|
173
|
+
// native inputs must equal the wanted-native output (if any) + change + fee.
|
|
174
|
+
const takerNativeIn = selection.selected.reduce((s, u) => s + u.satoshis, 0n);
|
|
175
|
+
(0, index_js_2.assertNativeConservation)([{ satoshis: takerNativeIn }], tx.outs, selection.fee, 'takeSellIdentityOffer');
|
|
176
|
+
const { signedTx, txid } = (0, sign_js_1.signTakerInputs)(tx.toHex(), takerInputs, params.wif, network);
|
|
177
|
+
return { swapTx: signedTx, txid };
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Build the maker's half of a buy-identity offer: spend the currency commitment
|
|
181
|
+
* with 0x83 into the single WANTED output — the identity transferred to the
|
|
182
|
+
* buyer's control. A taker who owns the identity completes the swap by spending
|
|
183
|
+
* the identity's current output and taking the offered currency.
|
|
184
|
+
*/
|
|
185
|
+
function buildBuyIdentityOffer(params, network) {
|
|
186
|
+
assertExpiryHeight(params.expiryHeight);
|
|
187
|
+
if (params.buyerPrimaryAddresses.length === 0) {
|
|
188
|
+
throw new errors_js_1.TransactionBuildError('buildBuyIdentityOffer: buyerPrimaryAddresses must not be empty');
|
|
189
|
+
}
|
|
190
|
+
const verusNetwork = (0, index_js_2.getNetwork)(network === 'testnet');
|
|
191
|
+
// The single wanted output: the identity transferred to the buyer.
|
|
192
|
+
const wantedScript = buildTransferredIdentity(params.identityJson, params.buyerPrimaryAddresses);
|
|
193
|
+
const txb = new boundary_js_1.TransactionBuilder(verusNetwork);
|
|
194
|
+
txb.setVersion(4);
|
|
195
|
+
txb.setExpiryHeight((0, index_js_2.resolveExpiryHeight)(params.expiryHeight));
|
|
196
|
+
txb.setVersionGroupId(index_js_5.VERSION_GROUP_ID);
|
|
197
|
+
txb.addInput(Buffer.from(params.commitment.txid, 'hex').reverse(), params.commitment.vout, 0xffffffff, Buffer.from(params.commitment.script, 'hex'));
|
|
198
|
+
txb.addOutput(wantedScript, 0);
|
|
199
|
+
const { signedTx, txid } = (0, sign_js_1.signOfferInput)(txb.buildIncomplete().toHex(), 0, Buffer.from(params.commitment.script, 'hex'), params.commitment.value, params.wif, network);
|
|
200
|
+
return { offerTx: signedTx, txid };
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Complete a buy-identity offer: give up the identity (spend its current output),
|
|
204
|
+
* receive the offered currency, and sign the seller's side. The identity flows to
|
|
205
|
+
* the buyer via the maker's already-committed output 0; the seller adds the
|
|
206
|
+
* identity input, the currency-to-seller output, native for the fee, and change.
|
|
207
|
+
*/
|
|
208
|
+
function completeBuyIdentityOffer(params, network) {
|
|
209
|
+
const verusNetwork = (0, index_js_2.getNetwork)(network === 'testnet');
|
|
210
|
+
const systemId = index_js_5.NETWORK_CONFIG[network].chainId;
|
|
211
|
+
const offeringNative = params.offered.currency === systemId;
|
|
212
|
+
if (params.offered.amount <= 0n) {
|
|
213
|
+
throw new errors_js_1.TransactionBuildError('completeBuyIdentityOffer: offered.amount must be positive');
|
|
214
|
+
}
|
|
215
|
+
const tx = boundary_js_1.Transaction.fromHex(params.offerTx, verusNetwork);
|
|
216
|
+
if (tx.ins.length !== 1 || tx.outs.length !== 1) {
|
|
217
|
+
throw new errors_js_1.TransactionBuildError('completeBuyIdentityOffer: expected a maker offer partial (1 input, 1 output)');
|
|
218
|
+
}
|
|
219
|
+
// The native value on the maker's currency commitment (input 0): the offered
|
|
220
|
+
// amount if native, else 0 (a token commitment carries 0 native).
|
|
221
|
+
const commitmentNative = offeringNative ? params.offered.amount : 0n;
|
|
222
|
+
// Input 1: the seller's identity output (spent, transferring the identity away).
|
|
223
|
+
const idIdx = tx.addInput(Buffer.from(params.identityOutput.txid, 'hex').reverse(), params.identityOutput.vout, 0xffffffff);
|
|
224
|
+
const takerInputs = [
|
|
225
|
+
{ index: idIdx, prevOutScript: Buffer.from(params.identityOutput.script, 'hex'), value: 0n },
|
|
226
|
+
];
|
|
227
|
+
// Output 1: the offered currency paid to the seller — plain payment for the
|
|
228
|
+
// native coin, a reserve output for a token.
|
|
229
|
+
if (offeringNative) {
|
|
230
|
+
tx.addOutput(nativePaymentScript(params.sellerReceiveAddress), (0, index_js_4.toSafeNumber)(params.offered.amount));
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
const out = (0, index_js_3.buildTokenChangeOutput)((0, brands_js_1.parseAddress)(params.sellerReceiveAddress, 'sellerReceiveAddress'), new Map([[params.offered.currency, params.offered.amount]]));
|
|
234
|
+
tx.addOutput(out.script, 0);
|
|
235
|
+
}
|
|
236
|
+
// The seller funds only the miner fee (native): select native-only UTXOs owned
|
|
237
|
+
// by wif, add change, assert conservation (commitment native + fee inputs), sign.
|
|
238
|
+
return fundFeeAndSignIdentityTaker({
|
|
239
|
+
tx,
|
|
240
|
+
priorInputs: takerInputs,
|
|
241
|
+
extraInputNative: commitmentNative,
|
|
242
|
+
takerUtxos: params.takerUtxos,
|
|
243
|
+
changeAddress: params.changeAddress,
|
|
244
|
+
wif: params.wif,
|
|
245
|
+
network,
|
|
246
|
+
label: 'takeBuyIdentityOffer',
|
|
247
|
+
extraOutputBytes: 300,
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Build the maker's half of an identity-for-identity swap: spend the OFFERED
|
|
252
|
+
* identity's current primary output with 0x83 into the single WANTED output — the
|
|
253
|
+
* WANTED identity transferred to the maker's control. This is exactly a
|
|
254
|
+
* buy-identity offer whose currency commitment is replaced by the offered
|
|
255
|
+
* identity's output (which carries 0 native): input 0 gives up the offered
|
|
256
|
+
* identity, output 0 acquires the wanted one.
|
|
257
|
+
*/
|
|
258
|
+
function buildSwapIdentityOffer(params, network) {
|
|
259
|
+
// Validate here (with this function's own parameter name) rather than letting the
|
|
260
|
+
// buildBuyIdentityOffer delegate throw an error naming buyerPrimaryAddresses.
|
|
261
|
+
if (params.makerPrimaryAddresses.length === 0) {
|
|
262
|
+
throw new errors_js_1.TransactionBuildError('buildSwapIdentityOffer: makerPrimaryAddresses must not be empty');
|
|
263
|
+
}
|
|
264
|
+
return buildBuyIdentityOffer({
|
|
265
|
+
wif: params.wif,
|
|
266
|
+
commitment: {
|
|
267
|
+
txid: params.offeredIdentityOutput.txid,
|
|
268
|
+
vout: params.offeredIdentityOutput.vout,
|
|
269
|
+
value: 0n, // an identity primary output carries 0 native
|
|
270
|
+
script: params.offeredIdentityOutput.script,
|
|
271
|
+
},
|
|
272
|
+
identityJson: params.wantedIdentityJson,
|
|
273
|
+
buyerPrimaryAddresses: params.makerPrimaryAddresses,
|
|
274
|
+
expiryHeight: params.expiryHeight,
|
|
275
|
+
}, network);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Complete an identity-for-identity swap: give up the WANTED identity (spend its
|
|
279
|
+
* current output, transferring it to the maker via output 0), receive the OFFERED
|
|
280
|
+
* identity (transferred to `takerPrimaryAddresses`), and sign the taker's side.
|
|
281
|
+
* No currency moves — the taker funds only the miner fee.
|
|
282
|
+
*/
|
|
283
|
+
function completeSwapIdentityOffer(params, network) {
|
|
284
|
+
const verusNetwork = (0, index_js_2.getNetwork)(network === 'testnet');
|
|
285
|
+
if (params.takerPrimaryAddresses.length === 0) {
|
|
286
|
+
throw new errors_js_1.TransactionBuildError('completeSwapIdentityOffer: takerPrimaryAddresses must not be empty');
|
|
287
|
+
}
|
|
288
|
+
const tx = boundary_js_1.Transaction.fromHex(params.offerTx, verusNetwork);
|
|
289
|
+
if (tx.ins.length !== 1 || tx.outs.length !== 1) {
|
|
290
|
+
throw new errors_js_1.TransactionBuildError('completeSwapIdentityOffer: expected a maker offer partial (1 input, 1 output)');
|
|
291
|
+
}
|
|
292
|
+
// Output 1: the OFFERED identity transferred to the taker.
|
|
293
|
+
tx.addOutput(buildTransferredIdentity(params.offeredIdentityJson, params.takerPrimaryAddresses), 0);
|
|
294
|
+
// Input 1: the taker's WANTED identity output (spent, transferring it to the maker).
|
|
295
|
+
const idIdx = tx.addInput(Buffer.from(params.wantedIdentityOutput.txid, 'hex').reverse(), params.wantedIdentityOutput.vout, 0xffffffff);
|
|
296
|
+
const takerInputs = [
|
|
297
|
+
{ index: idIdx, prevOutScript: Buffer.from(params.wantedIdentityOutput.script, 'hex'), value: 0n },
|
|
298
|
+
];
|
|
299
|
+
// The taker funds only the miner fee (native): both identity inputs carry 0
|
|
300
|
+
// native. Two identity outputs + the maker input are already present but
|
|
301
|
+
// invisible to selectUtxos, so a generous byte allowance covers their fee.
|
|
302
|
+
return fundFeeAndSignIdentityTaker({
|
|
303
|
+
tx,
|
|
304
|
+
priorInputs: takerInputs,
|
|
305
|
+
extraInputNative: 0n,
|
|
306
|
+
takerUtxos: params.takerUtxos,
|
|
307
|
+
changeAddress: params.changeAddress,
|
|
308
|
+
wif: params.wif,
|
|
309
|
+
network,
|
|
310
|
+
label: 'takeSwapIdentityOffer',
|
|
311
|
+
extraOutputBytes: 500,
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/offers/identity.ts"],"names":[],"mappings":";;AA8JA,wDAWC;AA0BD,8DAoEC;AAsBD,sDAkCC;AA4BD,4DAwDC;AA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AA4E;IAC5E,yEAAyE;IACzE,2EAA2E;IAC3E,OAAO,2BAA2B,CAAC;QACjC,EAAE;QACF,WAAW,EAAE,WAAW;QACxB,gBAAgB,EAAE,EAAE;QACpB,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,OAAO;QACP,KAAK,EAAE,uBAAuB;QAC9B,gBAAgB,EAAE,GAAG;KACtB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Network } from '../constants/index.js';
|
|
2
|
+
import type { Utxo } from '../types/index.js';
|
|
3
|
+
/** An outpoint plus the data needed to spend it. */
|
|
4
|
+
export interface FundedOutpoint {
|
|
5
|
+
txid: string;
|
|
6
|
+
vout: number;
|
|
7
|
+
/** Native satoshis on the output. */
|
|
8
|
+
value: bigint;
|
|
9
|
+
/** The output's scriptPubKey (hex). */
|
|
10
|
+
script: string;
|
|
11
|
+
}
|
|
12
|
+
export interface BuildOfferFundingParams {
|
|
13
|
+
wif: string;
|
|
14
|
+
utxos: Utxo[];
|
|
15
|
+
changeAddress: string;
|
|
16
|
+
/** The maker's R-address that will control (and later spend) the commitment. */
|
|
17
|
+
makerAddress: string;
|
|
18
|
+
/**
|
|
19
|
+
* The asset being offered, locked into the commitment output: the native coin
|
|
20
|
+
* (currency = the chain id) or a token (currency = an i-address). For a token,
|
|
21
|
+
* `utxos` must include reserve UTXOs holding at least `amount` of it.
|
|
22
|
+
*/
|
|
23
|
+
offered: {
|
|
24
|
+
currency: string;
|
|
25
|
+
amount: bigint;
|
|
26
|
+
};
|
|
27
|
+
expiryHeight?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface BuildOfferFundingResult {
|
|
30
|
+
fundingTx: string;
|
|
31
|
+
txid: string;
|
|
32
|
+
fee: bigint;
|
|
33
|
+
/** The commitment outpoint to hand to buildOffer once this tx is broadcast. */
|
|
34
|
+
commitment: FundedOutpoint;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Step 1: fund the offer — lock the offered asset (the native coin or a token) in
|
|
38
|
+
* a commitment output. Broadcast the returned tx, then pass `commitment` to
|
|
39
|
+
* buildOffer.
|
|
40
|
+
*/
|
|
41
|
+
export declare function buildOfferFunding(params: BuildOfferFundingParams, network: Network): BuildOfferFundingResult;
|
|
42
|
+
/** What the maker wants in return: a currency paid to an address. */
|
|
43
|
+
export interface OfferWant {
|
|
44
|
+
/** Currency id (i-address) for a token, or the chain id for native. */
|
|
45
|
+
currency: string;
|
|
46
|
+
amount: bigint;
|
|
47
|
+
/** Where the wanted asset is paid (the maker's receiving address). */
|
|
48
|
+
address: string;
|
|
49
|
+
}
|
|
50
|
+
export interface BuildOfferParams {
|
|
51
|
+
wif: string;
|
|
52
|
+
/** The commitment outpoint from buildOfferFunding (after broadcast). */
|
|
53
|
+
commitment: FundedOutpoint;
|
|
54
|
+
want: OfferWant;
|
|
55
|
+
expiryHeight?: number;
|
|
56
|
+
}
|
|
57
|
+
export interface BuildOfferResult {
|
|
58
|
+
/** The maker's half-signed offer transaction (SIGHASH_SINGLE|ANYONECANPAY). */
|
|
59
|
+
offerTx: string;
|
|
60
|
+
txid: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Step 2: build the maker's offer transaction — spend the funding commitment into
|
|
64
|
+
* the single wanted output, signed 0x83 so a taker can complete the swap.
|
|
65
|
+
*/
|
|
66
|
+
export declare function buildOffer(params: BuildOfferParams, network: Network): BuildOfferResult;
|
|
67
|
+
//# sourceMappingURL=maker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maker.d.ts","sourceRoot":"","sources":["../../src/offers/maker.ts"],"names":[],"mappings":"AAsCA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAE9C,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G;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,OAAO,GAAG,gBAAgB,CA6DvF"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildOfferFunding = buildOfferFunding;
|
|
4
|
+
exports.buildOffer = buildOffer;
|
|
5
|
+
/**
|
|
6
|
+
* Building the maker's side of a marketplace offer (offline).
|
|
7
|
+
*
|
|
8
|
+
* Two transactions, mirroring the daemon's `makeoffer`:
|
|
9
|
+
*
|
|
10
|
+
* 1. FUNDING tx — moves the OFFERED asset into a CryptoCondition commitment
|
|
11
|
+
* output the maker controls (an EVAL_IDENTITY_COMMITMENT CC with a zero
|
|
12
|
+
* commitment hash, byte-identical to the daemon). Signed normally
|
|
13
|
+
* (SIGHASH_ALL) and broadcast; the offered value now sits in one outpoint.
|
|
14
|
+
*
|
|
15
|
+
* 2. OFFER tx — spends that commitment with SIGHASH_SINGLE|ANYONECANPAY (see
|
|
16
|
+
* signOfferInput) into a single WANTED output: a reserve output when a token
|
|
17
|
+
* is wanted, a plain P2PKH when native is wanted. This is the maker's HALF of
|
|
18
|
+
* the atomic swap; a taker completes it.
|
|
19
|
+
*
|
|
20
|
+
* Every byte-bearing piece here is verified byte-identical to the daemon's
|
|
21
|
+
* makeoffer output on VRSCTEST: the native funding commitment
|
|
22
|
+
* (`buildCommitmentScript` with a zero hash), the token funding commitment
|
|
23
|
+
* (`buildTokenCommitmentScript`), the wanted reserve output
|
|
24
|
+
* (`buildTokenChangeOutput`), and the 0x83 fulfillment.
|
|
25
|
+
*
|
|
26
|
+
* The offered asset may be the native coin or a token; the wanted asset may be
|
|
27
|
+
* the native coin or a token (all four combinations).
|
|
28
|
+
*/
|
|
29
|
+
const boundary_js_1 = require("../fork/boundary.js");
|
|
30
|
+
const assembler_js_1 = require("../assemble/assembler.js");
|
|
31
|
+
const index_js_1 = require("../identity/index.js");
|
|
32
|
+
const sign_js_1 = require("./sign.js");
|
|
33
|
+
const index_js_2 = require("../signing/index.js");
|
|
34
|
+
const index_js_3 = require("../utils/index.js");
|
|
35
|
+
const brands_js_1 = require("../core/brands.js");
|
|
36
|
+
const index_js_4 = require("../constants/index.js");
|
|
37
|
+
const errors_js_1 = require("../errors.js");
|
|
38
|
+
/**
|
|
39
|
+
* Step 1: fund the offer — lock the offered asset (the native coin or a token) in
|
|
40
|
+
* a commitment output. Broadcast the returned tx, then pass `commitment` to
|
|
41
|
+
* buildOffer.
|
|
42
|
+
*/
|
|
43
|
+
function buildOfferFunding(params, network) {
|
|
44
|
+
if (params.offered.amount <= 0n) {
|
|
45
|
+
throw new errors_js_1.TransactionBuildError('offered.amount must be positive');
|
|
46
|
+
}
|
|
47
|
+
const makerAddress = (0, brands_js_1.parseRAddress)(params.makerAddress, 'makerAddress');
|
|
48
|
+
const systemId = index_js_4.NETWORK_CONFIG[network].chainId;
|
|
49
|
+
const offeringNative = params.offered.currency === systemId;
|
|
50
|
+
// The commitment output: a 32-zero-hash commitment carrying the offered native
|
|
51
|
+
// value, or a token commitment (marker + TokenOutput) carrying the offered token
|
|
52
|
+
// as reserve value with 0 native. Both are byte-identical to the daemon.
|
|
53
|
+
const commitmentScript = offeringNative
|
|
54
|
+
? (0, index_js_1.buildCommitmentScript)(Buffer.alloc(32, 0), makerAddress)
|
|
55
|
+
: (0, index_js_1.buildTokenCommitmentScript)(params.offered.currency, params.offered.amount, makerAddress);
|
|
56
|
+
const commitmentOutput = offeringNative
|
|
57
|
+
? { script: commitmentScript, nativeSat: params.offered.amount }
|
|
58
|
+
: {
|
|
59
|
+
script: commitmentScript,
|
|
60
|
+
nativeSat: 0n,
|
|
61
|
+
carries: new Map([[params.offered.currency, params.offered.amount]]),
|
|
62
|
+
};
|
|
63
|
+
const assembled = (0, assembler_js_1.assembleAndSign)({
|
|
64
|
+
network,
|
|
65
|
+
wif: params.wif,
|
|
66
|
+
expiryHeight: params.expiryHeight ?? 0,
|
|
67
|
+
funding: params.utxos,
|
|
68
|
+
outputs: [commitmentOutput],
|
|
69
|
+
changeAddress: params.changeAddress,
|
|
70
|
+
fee: { policy: 'estimate' },
|
|
71
|
+
label: 'offer funding',
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
fundingTx: assembled.signedTx,
|
|
75
|
+
txid: assembled.txid,
|
|
76
|
+
fee: assembled.fee,
|
|
77
|
+
commitment: {
|
|
78
|
+
txid: assembled.txid,
|
|
79
|
+
vout: 0,
|
|
80
|
+
// Native satoshis on the commitment output — 0 for a token offer. This is
|
|
81
|
+
// the amount the offer input signs over (SIGHASH_SINGLE|ANYONECANPAY).
|
|
82
|
+
value: offeringNative ? params.offered.amount : 0n,
|
|
83
|
+
script: commitmentScript.toString('hex'),
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Step 2: build the maker's offer transaction — spend the funding commitment into
|
|
89
|
+
* the single wanted output, signed 0x83 so a taker can complete the swap.
|
|
90
|
+
*/
|
|
91
|
+
function buildOffer(params, network) {
|
|
92
|
+
const verusNetwork = (0, index_js_2.getNetwork)(network === 'testnet');
|
|
93
|
+
const systemId = index_js_4.NETWORK_CONFIG[network].chainId;
|
|
94
|
+
if (params.want.amount <= 0n) {
|
|
95
|
+
throw new errors_js_1.TransactionBuildError('want.amount must be positive');
|
|
96
|
+
}
|
|
97
|
+
// An offer MUST expire at a real future block height. Verified live on VRSCTEST:
|
|
98
|
+
// the daemon rejects an offer with expiryHeight 0 ("never expires") as expired
|
|
99
|
+
// and refuses to take it. This SDK is offline and can't check "future", but it
|
|
100
|
+
// fails closed on the one value the daemon definitively rejects. Pass
|
|
101
|
+
// currentBlockHeight + a margin (the daemon's own makeoffer uses +200).
|
|
102
|
+
if (params.expiryHeight === undefined ||
|
|
103
|
+
!Number.isInteger(params.expiryHeight) ||
|
|
104
|
+
params.expiryHeight <= 0) {
|
|
105
|
+
throw new errors_js_1.TransactionBuildError('expiryHeight (a positive future block height) is required for an offer; the daemon rejects a 0/never-expiring offer as expired. Use currentBlockHeight + a margin (e.g. +200).');
|
|
106
|
+
}
|
|
107
|
+
// The single wanted output: a reserve output for a token, a plain payment for native.
|
|
108
|
+
let wantedScript;
|
|
109
|
+
let wantedNative;
|
|
110
|
+
if (params.want.currency === systemId) {
|
|
111
|
+
// Want native → plain P2PKH (i-address → explicit P2ID), value = wanted amount.
|
|
112
|
+
wantedScript = params.want.address.startsWith('i')
|
|
113
|
+
? (0, index_js_1.identityPaymentScript)((0, brands_js_1.parseIAddress)(params.want.address, 'want.address'))
|
|
114
|
+
: (0, index_js_3.addressToScriptPubKey)(params.want.address);
|
|
115
|
+
wantedNative = params.want.amount;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// Want token → reserve output carrying the wanted currency; 0 native.
|
|
119
|
+
wantedScript = (0, index_js_1.buildTokenChangeOutput)((0, brands_js_1.parseAddress)(params.want.address, 'want.address'), new Map([[params.want.currency, params.want.amount]])).script;
|
|
120
|
+
wantedNative = 0n;
|
|
121
|
+
}
|
|
122
|
+
const txb = new boundary_js_1.TransactionBuilder(verusNetwork);
|
|
123
|
+
txb.setVersion(4);
|
|
124
|
+
txb.setExpiryHeight((0, index_js_2.resolveExpiryHeight)(params.expiryHeight));
|
|
125
|
+
txb.setVersionGroupId(index_js_4.VERSION_GROUP_ID);
|
|
126
|
+
txb.addInput(Buffer.from(params.commitment.txid, 'hex').reverse(), params.commitment.vout, 0xffffffff, Buffer.from(params.commitment.script, 'hex'));
|
|
127
|
+
txb.addOutput(wantedScript, (0, index_js_3.toSafeNumber)(wantedNative));
|
|
128
|
+
const unsignedHex = txb.buildIncomplete().toHex();
|
|
129
|
+
const { signedTx, txid } = (0, sign_js_1.signOfferInput)(unsignedHex, 0, Buffer.from(params.commitment.script, 'hex'), params.commitment.value, params.wif, network);
|
|
130
|
+
return { offerTx: signedTx, txid };
|
|
131
|
+
}
|
|
132
|
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CAAC;IAClB,GAAG,CAAC,eAAe,CAAC,IAAA,8BAAmB,EAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;IAC9D,GAAG,CAAC,iBAAiB,CAAC,2BAAgB,CAAC,CAAC;IACxC,GAAG,CAAC,QAAQ,CACV,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,OAAO,EAAE,EACpD,MAAM,CAAC,UAAU,CAAC,IAAI,EACtB,UAAU,EACV,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAC7C,CAAC;IACF,GAAG,CAAC,SAAS,CAAC,YAAY,EAAE,IAAA,uBAAY,EAAC,YAAY,CAAC,CAAC,CAAC;IAExD,MAAM,WAAW,GAAG,GAAG,CAAC,eAAe,EAAE,CAAC,KAAK,EAAE,CAAC;IAClD,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,IAAA,wBAAc,EACvC,WAAW,EACX,CAAC,EACD,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,EAC5C,MAAM,CAAC,UAAU,CAAC,KAAK,EACvB,MAAM,CAAC,GAAG,EACV,OAAO,CACR,CAAC;IACF,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The curated public surface of the offers module — Verus marketplace offers
|
|
3
|
+
* (fully on-chain atomic swaps), built and signed offline.
|
|
4
|
+
*
|
|
5
|
+
* An offer is one half of an atomic swap: the maker signs the OFFERED asset's
|
|
6
|
+
* output with SIGHASH_SINGLE|ANYONECANPAY (0x83), committing to a single WANTED
|
|
7
|
+
* output; a taker adds their own inputs/outputs and signs SIGHASH_ALL, and the two
|
|
8
|
+
* halves merge into one transaction. The OFFERED and WANTED assets may each be the
|
|
9
|
+
* native coin, a token, or a VerusID — every combination is covered:
|
|
10
|
+
*
|
|
11
|
+
* - Currency ↔ currency: `buildOfferFunding` + `buildOffer` (maker), `completeOffer`
|
|
12
|
+
* (taker). Handles native↔native, native↔token, token↔native, token↔token.
|
|
13
|
+
* - Sell a VerusID for currency: `buildSellIdentityOffer` + `completeSellIdentityOffer`.
|
|
14
|
+
* - Buy a VerusID with currency: `buildBuyIdentityOffer` + `completeBuyIdentityOffer`.
|
|
15
|
+
* - Swap a VerusID for a VerusID: `buildSwapIdentityOffer` + `completeSwapIdentityOffer`.
|
|
16
|
+
*
|
|
17
|
+
* The maker flows that offer a currency need a funding transaction first
|
|
18
|
+
* (`buildOfferFunding` → broadcast → `buildOffer`); the identity-sell and swap
|
|
19
|
+
* makers spend the identity's existing on-chain output directly, no funding tx.
|
|
20
|
+
* These are also available on the `VerusSDK` facade (which injects the network);
|
|
21
|
+
* this module is the standalone entry point for power users. The lower-level
|
|
22
|
+
* fulfillment signers (`signOfferInput`, `signTakerInputs`) stay internal.
|
|
23
|
+
*/
|
|
24
|
+
export { buildOfferFunding, buildOffer, } from './maker.js';
|
|
25
|
+
export { completeOffer, } from './taker.js';
|
|
26
|
+
export { buildSellIdentityOffer, completeSellIdentityOffer, buildBuyIdentityOffer, completeBuyIdentityOffer, buildSwapIdentityOffer, completeSwapIdentityOffer, } from './identity.js';
|
|
27
|
+
export type { FundedOutpoint, BuildOfferFundingParams, BuildOfferFundingResult, OfferWant, BuildOfferParams, BuildOfferResult, } from './maker.js';
|
|
28
|
+
export type { CompleteOfferParams, CompleteOfferResult } from './taker.js';
|
|
29
|
+
export type { BuildSellIdentityOfferParams, CompleteSellIdentityOfferParams, CompleteSellIdentityOfferResult, BuildBuyIdentityOfferParams, CompleteBuyIdentityOfferParams, CompleteBuyIdentityOfferResult, BuildSwapIdentityOfferParams, CompleteSwapIdentityOfferParams, CompleteSwapIdentityOfferResult, } from './identity.js';
|
|
30
|
+
//# sourceMappingURL=public.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/offers/public.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAEL,iBAAiB,EACjB,UAAU,GACX,MAAM,YAAY,CAAC;AACpB,OAAO,EAEL,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAEL,sBAAsB,EACtB,yBAAyB,EACzB,qBAAqB,EACrB,wBAAwB,EACxB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,eAAe,CAAC;AAEvB,YAAY,EACV,cAAc,EACd,uBAAuB,EACvB,uBAAuB,EACvB,SAAS,EACT,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC3E,YAAY,EACV,4BAA4B,EAC5B,+BAA+B,EAC/B,+BAA+B,EAC/B,2BAA2B,EAC3B,8BAA8B,EAC9B,8BAA8B,EAC9B,4BAA4B,EAC5B,+BAA+B,EAC/B,+BAA+B,GAChC,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.completeSwapIdentityOffer = exports.buildSwapIdentityOffer = exports.completeBuyIdentityOffer = exports.buildBuyIdentityOffer = exports.completeSellIdentityOffer = exports.buildSellIdentityOffer = exports.completeOffer = exports.buildOffer = exports.buildOfferFunding = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The curated public surface of the offers module — Verus marketplace offers
|
|
6
|
+
* (fully on-chain atomic swaps), built and signed offline.
|
|
7
|
+
*
|
|
8
|
+
* An offer is one half of an atomic swap: the maker signs the OFFERED asset's
|
|
9
|
+
* output with SIGHASH_SINGLE|ANYONECANPAY (0x83), committing to a single WANTED
|
|
10
|
+
* output; a taker adds their own inputs/outputs and signs SIGHASH_ALL, and the two
|
|
11
|
+
* halves merge into one transaction. The OFFERED and WANTED assets may each be the
|
|
12
|
+
* native coin, a token, or a VerusID — every combination is covered:
|
|
13
|
+
*
|
|
14
|
+
* - Currency ↔ currency: `buildOfferFunding` + `buildOffer` (maker), `completeOffer`
|
|
15
|
+
* (taker). Handles native↔native, native↔token, token↔native, token↔token.
|
|
16
|
+
* - Sell a VerusID for currency: `buildSellIdentityOffer` + `completeSellIdentityOffer`.
|
|
17
|
+
* - Buy a VerusID with currency: `buildBuyIdentityOffer` + `completeBuyIdentityOffer`.
|
|
18
|
+
* - Swap a VerusID for a VerusID: `buildSwapIdentityOffer` + `completeSwapIdentityOffer`.
|
|
19
|
+
*
|
|
20
|
+
* The maker flows that offer a currency need a funding transaction first
|
|
21
|
+
* (`buildOfferFunding` → broadcast → `buildOffer`); the identity-sell and swap
|
|
22
|
+
* makers spend the identity's existing on-chain output directly, no funding tx.
|
|
23
|
+
* These are also available on the `VerusSDK` facade (which injects the network);
|
|
24
|
+
* this module is the standalone entry point for power users. The lower-level
|
|
25
|
+
* fulfillment signers (`signOfferInput`, `signTakerInputs`) stay internal.
|
|
26
|
+
*/
|
|
27
|
+
var maker_js_1 = require("./maker.js");
|
|
28
|
+
// Currency-offer maker: fund the offered asset, then build the half-signed offer.
|
|
29
|
+
Object.defineProperty(exports, "buildOfferFunding", { enumerable: true, get: function () { return maker_js_1.buildOfferFunding; } });
|
|
30
|
+
Object.defineProperty(exports, "buildOffer", { enumerable: true, get: function () { return maker_js_1.buildOffer; } });
|
|
31
|
+
var taker_js_1 = require("./taker.js");
|
|
32
|
+
// Currency-offer taker: complete and sign the swap.
|
|
33
|
+
Object.defineProperty(exports, "completeOffer", { enumerable: true, get: function () { return taker_js_1.completeOffer; } });
|
|
34
|
+
var identity_js_1 = require("./identity.js");
|
|
35
|
+
// Identity-offer flows (sell / buy / swap), maker + taker halves.
|
|
36
|
+
Object.defineProperty(exports, "buildSellIdentityOffer", { enumerable: true, get: function () { return identity_js_1.buildSellIdentityOffer; } });
|
|
37
|
+
Object.defineProperty(exports, "completeSellIdentityOffer", { enumerable: true, get: function () { return identity_js_1.completeSellIdentityOffer; } });
|
|
38
|
+
Object.defineProperty(exports, "buildBuyIdentityOffer", { enumerable: true, get: function () { return identity_js_1.buildBuyIdentityOffer; } });
|
|
39
|
+
Object.defineProperty(exports, "completeBuyIdentityOffer", { enumerable: true, get: function () { return identity_js_1.completeBuyIdentityOffer; } });
|
|
40
|
+
Object.defineProperty(exports, "buildSwapIdentityOffer", { enumerable: true, get: function () { return identity_js_1.buildSwapIdentityOffer; } });
|
|
41
|
+
Object.defineProperty(exports, "completeSwapIdentityOffer", { enumerable: true, get: function () { return identity_js_1.completeSwapIdentityOffer; } });
|
|
42
|
+
//# sourceMappingURL=public.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public.js","sourceRoot":"","sources":["../../src/offers/public.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,uCAIoB;AAHlB,kFAAkF;AAClF,6GAAA,iBAAiB,OAAA;AACjB,sGAAA,UAAU,OAAA;AAEZ,uCAGoB;AAFlB,oDAAoD;AACpD,yGAAA,aAAa,OAAA;AAEf,6CAQuB;AAPrB,kEAAkE;AAClE,qHAAA,sBAAsB,OAAA;AACtB,wHAAA,yBAAyB,OAAA;AACzB,oHAAA,qBAAqB,OAAA;AACrB,uHAAA,wBAAwB,OAAA;AACxB,qHAAA,sBAAsB,OAAA;AACtB,wHAAA,yBAAyB,OAAA"}
|