@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
package/README.md
CHANGED
|
@@ -35,6 +35,10 @@ const { signedTx, txid, fee } = sdk.transfer({
|
|
|
35
35
|
- **VerusID** — `createCommitment` → `registerIdentity` (incl. sub-IDs), then
|
|
36
36
|
`updateIdentity` / `lockIdentity` / `unlockIdentity` / `revokeIdentity` /
|
|
37
37
|
`recoverIdentity`, plus `signMessage` / `verifyMessage`.
|
|
38
|
+
- **Marketplace offers** — build and complete fully on-chain atomic swaps:
|
|
39
|
+
currency↔currency (`buildOfferFunding` → `buildOffer` → `completeOffer`), and
|
|
40
|
+
VerusID sell / buy / swap (`build*IdentityOffer` / `complete*IdentityOffer`).
|
|
41
|
+
Native coin, tokens, and identities, in every combination.
|
|
38
42
|
- **Helpers** — `VerusSDK.generateWif()`, `deriveAddress(wif)`,
|
|
39
43
|
`deriveIdentityAddress(name, parent?)`, `validateAddress`, `validateWif`;
|
|
40
44
|
`utils.summarizeSignedTransaction(hex)` decodes a signed tx (txid, spent
|
|
@@ -65,7 +69,9 @@ Per-area guides, plus runnable offline examples in [`examples/`](./examples):
|
|
|
65
69
|
| [amounts](./docs/amounts.md) | the money model — `bigint` satoshis, `parseSats`/`toCoins`, the one float64 boundary |
|
|
66
70
|
| [transfers](./docs/transfers.md) | `transfer` / `transferToken` / `convert` / `sendCurrency`, UTXOs, change, re-validation |
|
|
67
71
|
| [VerusID lifecycle](./docs/identity.md) | commit → register, update, lock/unlock, revoke/recover, sign/verify messages |
|
|
72
|
+
| [marketplace offers](./docs/offers.md) | atomic-swap model, the maker/taker halves, currency↔currency and VerusID sell/buy/swap |
|
|
68
73
|
| [signing & wire format](./docs/signing-and-wire.md) | why the bytes are the daemon's, the self-contained bundle, the proof rings |
|
|
74
|
+
| [architecture](./docs/architecture.md) | the fork boundary, the two assemblers, what's unrepresentable vs checked, the differential harness |
|
|
69
75
|
| [testing](./docs/testing.md) | the gate, the plain-`node` rule, the live-proof ring model |
|
|
70
76
|
|
|
71
77
|
## Contributing
|
package/dist/VerusSDK.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { Network } from './constants/index.js';
|
|
8
8
|
import type { VerusSDKConfig, TransferParams, TransferTokenParams, ConvertParams, SendCurrencyParams, SendCurrencyResult, BuildAndSignParams, SignedTxResult, CreateCommitmentParams, CreateCommitmentResult, RegisterIdentityParams, RegisterIdentityResult, UpdateIdentityParams, UpdateIdentityResult, LockIdentityParams, UnlockIdentityParams, RevokeIdentityParams, RecoverIdentityParams, DefineCurrencyParams, DefineCurrencyResult, SignMessageParams, SignMessageResult, VerifyMessageParams, VerifyMessageResult } from './types/index.js';
|
|
9
|
+
import type { BuildOfferFundingParams, BuildOfferFundingResult, BuildOfferParams, BuildOfferResult, CompleteOfferParams, CompleteOfferResult, BuildSellIdentityOfferParams, CompleteSellIdentityOfferParams, CompleteSellIdentityOfferResult, BuildBuyIdentityOfferParams, CompleteBuyIdentityOfferParams, CompleteBuyIdentityOfferResult, BuildSwapIdentityOfferParams, CompleteSwapIdentityOfferParams, CompleteSwapIdentityOfferResult } from './offers/public.js';
|
|
9
10
|
export declare class VerusSDK {
|
|
10
11
|
readonly network: Network;
|
|
11
12
|
constructor(config: VerusSDKConfig);
|
|
@@ -42,6 +43,33 @@ export declare class VerusSDK {
|
|
|
42
43
|
signMessage(params: SignMessageParams): SignMessageResult;
|
|
43
44
|
/** Verify a VerusID message signature */
|
|
44
45
|
verifyMessage(params: VerifyMessageParams): VerifyMessageResult;
|
|
46
|
+
/**
|
|
47
|
+
* Maker step 1 (currency offers only): fund the OFFERED asset into a commitment
|
|
48
|
+
* output. Broadcast the returned tx, then pass `commitment` to `buildOffer`.
|
|
49
|
+
*/
|
|
50
|
+
buildOfferFunding(params: BuildOfferFundingParams): BuildOfferFundingResult;
|
|
51
|
+
/**
|
|
52
|
+
* Maker step 2 (currency offers): build the half-signed offer — spend the funded
|
|
53
|
+
* commitment with 0x83, committing to the single WANTED output paid to the maker.
|
|
54
|
+
*/
|
|
55
|
+
buildOffer(params: BuildOfferParams): BuildOfferResult;
|
|
56
|
+
/**
|
|
57
|
+
* Taker (currency offers): complete the maker's offer — pay the wanted asset,
|
|
58
|
+
* receive the offered asset, and sign the taker's side into an atomic swap.
|
|
59
|
+
*/
|
|
60
|
+
completeOffer(params: CompleteOfferParams): CompleteOfferResult;
|
|
61
|
+
/** Maker: offer a VerusID for a currency (spends the identity's on-chain output). */
|
|
62
|
+
buildSellIdentityOffer(params: BuildSellIdentityOfferParams): BuildOfferResult;
|
|
63
|
+
/** Taker: complete a sell-identity offer — pay the currency, receive the identity. */
|
|
64
|
+
completeSellIdentityOffer(params: CompleteSellIdentityOfferParams): CompleteSellIdentityOfferResult;
|
|
65
|
+
/** Maker: offer a currency for a VerusID (funds the currency into a commitment). */
|
|
66
|
+
buildBuyIdentityOffer(params: BuildBuyIdentityOfferParams): BuildOfferResult;
|
|
67
|
+
/** Taker (identity owner): complete a buy-identity offer — give up the identity, take the currency. */
|
|
68
|
+
completeBuyIdentityOffer(params: CompleteBuyIdentityOfferParams): CompleteBuyIdentityOfferResult;
|
|
69
|
+
/** Maker: offer a VerusID for another VerusID (no currency moves). */
|
|
70
|
+
buildSwapIdentityOffer(params: BuildSwapIdentityOfferParams): BuildOfferResult;
|
|
71
|
+
/** Taker (owns the wanted identity): complete an identity swap — funds only the miner fee. */
|
|
72
|
+
completeSwapIdentityOffer(params: CompleteSwapIdentityOfferParams): CompleteSwapIdentityOfferResult;
|
|
45
73
|
/** Derive R-address from WIF private key */
|
|
46
74
|
static deriveAddress(wif: string): Promise<string>;
|
|
47
75
|
/** Derive identity i-address from a name and optional parent */
|
package/dist/VerusSDK.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VerusSDK.d.ts","sourceRoot":"","sources":["../src/VerusSDK.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACd,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"VerusSDK.d.ts","sourceRoot":"","sources":["../src/VerusSDK.ts"],"names":[],"m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GAAG,+BAA+B;IAMnG,4CAA4C;WAC/B,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIxD,gEAAgE;IAChE,MAAM,CAAC,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM;IAI3E,4CAA4C;IAC5C,MAAM,CAAC,WAAW,IAAI,MAAM;IAI5B,iCAAiC;IACjC,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IAI3E,iCAAiC;IACjC,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;CAGpE"}
|
package/dist/VerusSDK.js
CHANGED
|
@@ -45,6 +45,7 @@ const identityModule = __importStar(require("./identity/index.js"));
|
|
|
45
45
|
const messageModule = __importStar(require("./message/index.js"));
|
|
46
46
|
const currencyModule = __importStar(require("./currency/index.js"));
|
|
47
47
|
const keysModule = __importStar(require("./keys/index.js"));
|
|
48
|
+
const offersModule = __importStar(require("./offers/public.js"));
|
|
48
49
|
class VerusSDK {
|
|
49
50
|
constructor(config) {
|
|
50
51
|
this.network = config.network;
|
|
@@ -148,6 +149,52 @@ class VerusSDK {
|
|
|
148
149
|
verifyMessage(params) {
|
|
149
150
|
return messageModule.verifyMessage(params, this.network);
|
|
150
151
|
}
|
|
152
|
+
// ─── Marketplace Offers (atomic swaps) ─────────────
|
|
153
|
+
/**
|
|
154
|
+
* Maker step 1 (currency offers only): fund the OFFERED asset into a commitment
|
|
155
|
+
* output. Broadcast the returned tx, then pass `commitment` to `buildOffer`.
|
|
156
|
+
*/
|
|
157
|
+
buildOfferFunding(params) {
|
|
158
|
+
return offersModule.buildOfferFunding(params, this.network);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Maker step 2 (currency offers): build the half-signed offer — spend the funded
|
|
162
|
+
* commitment with 0x83, committing to the single WANTED output paid to the maker.
|
|
163
|
+
*/
|
|
164
|
+
buildOffer(params) {
|
|
165
|
+
return offersModule.buildOffer(params, this.network);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Taker (currency offers): complete the maker's offer — pay the wanted asset,
|
|
169
|
+
* receive the offered asset, and sign the taker's side into an atomic swap.
|
|
170
|
+
*/
|
|
171
|
+
completeOffer(params) {
|
|
172
|
+
return offersModule.completeOffer(params, this.network);
|
|
173
|
+
}
|
|
174
|
+
/** Maker: offer a VerusID for a currency (spends the identity's on-chain output). */
|
|
175
|
+
buildSellIdentityOffer(params) {
|
|
176
|
+
return offersModule.buildSellIdentityOffer(params, this.network);
|
|
177
|
+
}
|
|
178
|
+
/** Taker: complete a sell-identity offer — pay the currency, receive the identity. */
|
|
179
|
+
completeSellIdentityOffer(params) {
|
|
180
|
+
return offersModule.completeSellIdentityOffer(params, this.network);
|
|
181
|
+
}
|
|
182
|
+
/** Maker: offer a currency for a VerusID (funds the currency into a commitment). */
|
|
183
|
+
buildBuyIdentityOffer(params) {
|
|
184
|
+
return offersModule.buildBuyIdentityOffer(params, this.network);
|
|
185
|
+
}
|
|
186
|
+
/** Taker (identity owner): complete a buy-identity offer — give up the identity, take the currency. */
|
|
187
|
+
completeBuyIdentityOffer(params) {
|
|
188
|
+
return offersModule.completeBuyIdentityOffer(params, this.network);
|
|
189
|
+
}
|
|
190
|
+
/** Maker: offer a VerusID for another VerusID (no currency moves). */
|
|
191
|
+
buildSwapIdentityOffer(params) {
|
|
192
|
+
return offersModule.buildSwapIdentityOffer(params, this.network);
|
|
193
|
+
}
|
|
194
|
+
/** Taker (owns the wanted identity): complete an identity swap — funds only the miner fee. */
|
|
195
|
+
completeSwapIdentityOffer(params) {
|
|
196
|
+
return offersModule.completeSwapIdentityOffer(params, this.network);
|
|
197
|
+
}
|
|
151
198
|
// ─── Static Utilities ─────────────────────────────
|
|
152
199
|
/** Derive R-address from WIF private key */
|
|
153
200
|
static async deriveAddress(wif) {
|
package/dist/VerusSDK.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VerusSDK.js","sourceRoot":"","sources":["../src/VerusSDK.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"VerusSDK.js","sourceRoot":"","sources":["../src/VerusSDK.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDH,oEAAsD;AACtD,oEAAsD;AACtD,kEAAoD;AACpD,oEAAsD;AACtD,4DAA8C;AAC9C,iEAAmD;AAEnD,MAAa,QAAQ;IAGnB,YAAY,MAAsB;QAChC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;IAChC,CAAC;IAED,sDAAsD;IAEtD,kDAAkD;IAClD,QAAQ,CAAC,MAAsB;QAC7B,OAAO,cAAc,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC;IAED,8BAA8B;IAC9B,aAAa,CAAC,MAA2B;QACvC,OAAO,cAAc,CAAC,aAAa,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;IAED,0BAA0B;IAC1B,OAAO,CAAC,MAAqB;QAC3B,OAAO,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACtD,CAAC;IAED,iEAAiE;IACjE,YAAY,CAAC,MAA0B;QACrC,OAAO,cAAc,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3D,CAAC;IAED,gDAAgD;IAChD,YAAY,CAAC,MAA0B;QACrC,OAAO,cAAc,CAAC,YAAY,CAAC,MAAM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
2
|
+
import type { Utxo } from '../types/index.js';
|
|
3
|
+
/** One output the caller declares. */
|
|
4
|
+
export interface IntentOutput {
|
|
5
|
+
/** Pre-built output scriptPubKey (identity, reservation, fee, payment, …). */
|
|
6
|
+
script: Buffer;
|
|
7
|
+
/** Native satoshis carried on the output. */
|
|
8
|
+
nativeSat: bigint;
|
|
9
|
+
/** Non-native currencies the script pays out (e.g. a reserve fee output) — used
|
|
10
|
+
* to derive the token funding requirement and the token-conservation check. */
|
|
11
|
+
carries?: Map<string, bigint>;
|
|
12
|
+
}
|
|
13
|
+
export interface TxIntent {
|
|
14
|
+
network: Network;
|
|
15
|
+
/** WIF signing every input (single-key paths only). */
|
|
16
|
+
wif: string;
|
|
17
|
+
expiryHeight: number;
|
|
18
|
+
funding: Utxo[];
|
|
19
|
+
/** Inputs added before the funding inputs (e.g. a name-commitment UTXO). They
|
|
20
|
+
* carry 0 token value; their native value folds into the fee. */
|
|
21
|
+
leadingInputs?: Utxo[];
|
|
22
|
+
/** Declared outputs, emitted in order before change. */
|
|
23
|
+
outputs: IntentOutput[];
|
|
24
|
+
changeAddress: string;
|
|
25
|
+
/** Whether the outputs are CryptoCondition (smart) outputs — drives fee sizing. */
|
|
26
|
+
hasSmartOutputs?: boolean;
|
|
27
|
+
/** Extra bytes for fee sizing when a pre-built output dwarfs the fixed estimate. */
|
|
28
|
+
extraOutputBytes?: number;
|
|
29
|
+
/** Output count fed to the fee estimator; defaults to the declared outputs.
|
|
30
|
+
* Override only to reproduce a legacy per-path estimate byte-for-byte. */
|
|
31
|
+
feeOutputCount?: number;
|
|
32
|
+
/** Token funding requirement, when the outputs are pre-built by the fork
|
|
33
|
+
* (createUnfundedCurrencyTransfer) and their carried token value can't be read
|
|
34
|
+
* back off the opaque scripts. When set, it REPLACES the per-output `carries`
|
|
35
|
+
* derivation. Drives both selection and the token-conservation check. */
|
|
36
|
+
requiredCurrencies?: Map<string, bigint>;
|
|
37
|
+
/** How change is emitted. `bundled` (default) rides the native change on the
|
|
38
|
+
* token-change reserve output (the identity/registration convention). `separate`
|
|
39
|
+
* emits the token change with only its structural native value plus a distinct
|
|
40
|
+
* native-change output (the fork's currency-transfer convention). */
|
|
41
|
+
changeStrategy?: 'bundled' | 'separate';
|
|
42
|
+
/** `estimate` sizes the fee from the tx. `declared` names an intentional
|
|
43
|
+
* implicit burn — native that leaves BEYOND the outputs and the miner fee
|
|
44
|
+
* (e.g. the registration fee): it is added to the funding requirement and
|
|
45
|
+
* bounds the signing-time fee-rate cap, so it can never be an accident. */
|
|
46
|
+
fee: {
|
|
47
|
+
policy: 'estimate';
|
|
48
|
+
} | {
|
|
49
|
+
policy: 'declared';
|
|
50
|
+
burnSat: bigint;
|
|
51
|
+
reason: string;
|
|
52
|
+
};
|
|
53
|
+
/** Label used in conservation error messages. */
|
|
54
|
+
label: string;
|
|
55
|
+
}
|
|
56
|
+
export interface AssembledTx {
|
|
57
|
+
signedTx: string;
|
|
58
|
+
txid: string;
|
|
59
|
+
fee: bigint;
|
|
60
|
+
nativeChange: bigint;
|
|
61
|
+
currencyChanges: Map<string, bigint>;
|
|
62
|
+
selected: Utxo[];
|
|
63
|
+
inputsUsed: number;
|
|
64
|
+
}
|
|
65
|
+
export declare function assembleAndSign(intent: TxIntent): AssembledTx;
|
|
66
|
+
//# sourceMappingURL=assembler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assembler.d.ts","sourceRoot":"","sources":["../../src/assemble/assembler.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAE9C,sCAAsC;AACtC,MAAM,WAAW,YAAY;IAC3B,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB;oFACgF;IAChF,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM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 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assembleAndSign = assembleAndSign;
|
|
4
|
+
/**
|
|
5
|
+
* The single transaction assembler.
|
|
6
|
+
*
|
|
7
|
+
* Every value-moving path funnels through here as a thin `TxIntent`: the caller
|
|
8
|
+
* declares its inputs and the outputs it wants (with each output's native value
|
|
9
|
+
* and any token value the script carries); the assembler derives the funding
|
|
10
|
+
* requirements, selects UTXOs, emits change, and enforces native + token value
|
|
11
|
+
* conservation on the assembled transaction BY CONSTRUCTION. A path can no
|
|
12
|
+
* longer forget a conservation assert, drop token change, or hand-roll a
|
|
13
|
+
* change-emission block that drifts from the others — those were whole classes
|
|
14
|
+
* of bug. Fees are either estimated (selectUtxos) or DECLARED with an intent
|
|
15
|
+
* (registration's implicit burn); an unnamed implicit fee is unrepresentable.
|
|
16
|
+
*
|
|
17
|
+
* Ported flows must stay byte-identical to the Phase-0 golden snapshots.
|
|
18
|
+
*/
|
|
19
|
+
const boundary_js_1 = require("../fork/boundary.js");
|
|
20
|
+
const index_js_1 = require("../utxo/index.js");
|
|
21
|
+
const index_js_2 = require("../signing/index.js");
|
|
22
|
+
const index_js_3 = require("../utils/index.js");
|
|
23
|
+
const index_js_4 = require("../constants/index.js");
|
|
24
|
+
const index_js_5 = require("../identity/index.js");
|
|
25
|
+
const brands_js_1 = require("../core/brands.js");
|
|
26
|
+
const errors_js_1 = require("../errors.js");
|
|
27
|
+
function assembleAndSign(intent) {
|
|
28
|
+
const verusNetwork = (0, index_js_2.getNetwork)(intent.network === 'testnet');
|
|
29
|
+
const systemId = index_js_4.NETWORK_CONFIG[intent.network].chainId;
|
|
30
|
+
// Leading inputs sit OUTSIDE the token-conservation check below (which only
|
|
31
|
+
// sees the funding selection), so a leading input carrying token value would be
|
|
32
|
+
// silently burned. Fail closed. Today the only leading input is the SDK-built
|
|
33
|
+
// name-commitment UTXO, which carries none — this enforces the assumption the
|
|
34
|
+
// TxIntent doc states instead of trusting it.
|
|
35
|
+
for (const u of intent.leadingInputs ?? []) {
|
|
36
|
+
// Native on a leading input folds into the fee (burned to miner), so reject it
|
|
37
|
+
// — matching the identity-respend assembler, which fails closed on a nonzero
|
|
38
|
+
// identity UTXO. A name-commitment output is value 0.
|
|
39
|
+
if (u.satoshis !== 0n) {
|
|
40
|
+
throw new errors_js_1.TransactionBuildError(`${intent.label}: leading input ${u.txid}:${u.outputIndex} carries ${u.satoshis} native satoshis, ` +
|
|
41
|
+
`which would be burned to miner fee. Spend that value separately first.`);
|
|
42
|
+
}
|
|
43
|
+
let currencyValues;
|
|
44
|
+
try {
|
|
45
|
+
({ currencyValues } = (0, index_js_1.decodeUtxo)(u, systemId));
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// Undecodable smart output — e.g. the name-commitment's eval-17 CC, which
|
|
49
|
+
// unpackOutput doesn't model. It is not a reserve output, so it carries no
|
|
50
|
+
// token value. A token-bearing leading input IS a reserve output (eval 8/9)
|
|
51
|
+
// and decodes cleanly, so it is still caught below.
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
for (const [currency, amount] of currencyValues) {
|
|
55
|
+
if (currency !== systemId && amount > 0n) {
|
|
56
|
+
throw new errors_js_1.TransactionBuildError(`${intent.label}: leading input ${u.txid}:${u.outputIndex} carries ${amount} of ${currency}, ` +
|
|
57
|
+
`which is outside token conservation and would be burned. Fund token-bearing inputs through the funding path.`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Funding requirements are DERIVED from the declared outputs — never restated
|
|
62
|
+
// by the caller (the token-burn class came from a path building these by hand).
|
|
63
|
+
// A declared implicit burn (registration fee) is native that must be funded
|
|
64
|
+
// but leaves as fee rather than to an output, so it adds to the native need.
|
|
65
|
+
const burnSat = intent.fee.policy === 'declared' ? intent.fee.burnSat : 0n;
|
|
66
|
+
let requiredNative = burnSat;
|
|
67
|
+
// Token requirement: an explicit override (fork-built outputs) replaces the
|
|
68
|
+
// per-output carries; otherwise it is summed from the outputs' declared carries.
|
|
69
|
+
const requiredCurrencies = new Map(intent.requiredCurrencies ?? []);
|
|
70
|
+
for (const o of intent.outputs) {
|
|
71
|
+
requiredNative += o.nativeSat;
|
|
72
|
+
if (!intent.requiredCurrencies && o.carries) {
|
|
73
|
+
for (const [c, v] of o.carries)
|
|
74
|
+
requiredCurrencies.set(c, (requiredCurrencies.get(c) ?? 0n) + v);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const selection = (0, index_js_1.selectUtxos)(intent.funding, requiredNative, requiredCurrencies, intent.feeOutputCount ?? intent.outputs.length, systemId, undefined, intent.hasSmartOutputs ?? true, intent.extraOutputBytes ?? 0);
|
|
78
|
+
const txb = new boundary_js_1.TransactionBuilder(verusNetwork);
|
|
79
|
+
txb.setVersion(4);
|
|
80
|
+
txb.setExpiryHeight((0, index_js_2.resolveExpiryHeight)(intent.expiryHeight));
|
|
81
|
+
txb.setVersionGroupId(index_js_4.VERSION_GROUP_ID);
|
|
82
|
+
const leading = intent.leadingInputs ?? [];
|
|
83
|
+
const allUtxos = [...leading, ...selection.selected];
|
|
84
|
+
for (const utxo of allUtxos) {
|
|
85
|
+
txb.addInput(Buffer.from(utxo.txid, 'hex').reverse(), utxo.outputIndex, 0xffffffff, Buffer.from(utxo.script, 'hex'));
|
|
86
|
+
}
|
|
87
|
+
for (const o of intent.outputs) {
|
|
88
|
+
txb.addOutput(o.script, (0, index_js_3.toSafeNumber)(o.nativeSat));
|
|
89
|
+
}
|
|
90
|
+
// Change, emitted in one place — bundled onto the reserve output or as a
|
|
91
|
+
// separate native output (per changeStrategy). utxo-lib's addOutput only
|
|
92
|
+
// resolves base58 R-addresses, so an i-address change needs the explicit P2ID
|
|
93
|
+
// script.
|
|
94
|
+
const hasTokenChange = selection.currencyChanges.size > 0;
|
|
95
|
+
const emitNativeChange = (value) => {
|
|
96
|
+
if (intent.changeAddress.startsWith('i')) {
|
|
97
|
+
txb.addOutput((0, index_js_5.identityPaymentScript)((0, brands_js_1.parseIAddress)(intent.changeAddress, 'changeAddress')), (0, index_js_3.toSafeNumber)(value));
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
txb.addOutput(intent.changeAddress, (0, index_js_3.toSafeNumber)(value));
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
if ((intent.changeStrategy ?? 'bundled') === 'separate') {
|
|
104
|
+
// Token change carries only its own structural native value; the native change
|
|
105
|
+
// is a distinct output (the fork's currency-transfer convention).
|
|
106
|
+
if (hasTokenChange) {
|
|
107
|
+
const tokenChange = (0, index_js_5.buildTokenChangeOutput)((0, brands_js_1.parseAddress)(intent.changeAddress, 'changeAddress'), selection.currencyChanges);
|
|
108
|
+
txb.addOutput(tokenChange.script, (0, index_js_3.toSafeNumber)(tokenChange.nativeValue));
|
|
109
|
+
}
|
|
110
|
+
if (selection.nativeChange > 0n)
|
|
111
|
+
emitNativeChange(selection.nativeChange);
|
|
112
|
+
}
|
|
113
|
+
else if (hasTokenChange || selection.nativeChange > 0n) {
|
|
114
|
+
// Bundled: the native change rides on the token-change reserve output.
|
|
115
|
+
if (hasTokenChange) {
|
|
116
|
+
const tokenChange = (0, index_js_5.buildTokenChangeOutput)((0, brands_js_1.parseAddress)(intent.changeAddress, 'changeAddress'), selection.currencyChanges);
|
|
117
|
+
txb.addOutput(tokenChange.script, (0, index_js_3.toSafeNumber)(selection.nativeChange));
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
emitNativeChange(selection.nativeChange);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const unsignedTx = txb.buildIncomplete();
|
|
124
|
+
// Conservation postconditions on the assembled transaction.
|
|
125
|
+
//
|
|
126
|
+
// The token check is a CONSISTENCY check, not an independent audit:
|
|
127
|
+
// selection.currencyChanges was computed by selectUtxos as (inputs −
|
|
128
|
+
// requiredCurrencies), so `inputs == requiredCurrencies + change` holds by
|
|
129
|
+
// construction. It catches a re-decode disagreement between the two calls, or a
|
|
130
|
+
// `requiredCurrencies` override (sendCurrency) that doesn't match the funded
|
|
131
|
+
// token value — NOT a per-currency semantic error. For currency transfers, the
|
|
132
|
+
// semantic audit (conversion, export, fee-currency accounting) is
|
|
133
|
+
// validateFundedTransaction, which sendCurrency runs on the signed hex.
|
|
134
|
+
(0, index_js_1.assertTokenConservation)(selection.selected, requiredCurrencies, selection.currencyChanges, systemId, intent.label);
|
|
135
|
+
// The native check IS an independent audit: inputs − outputs must equal the
|
|
136
|
+
// intended fee = miner fee + any declared burn. Leading inputs are guarded to 0
|
|
137
|
+
// native above, so their term is 0; it stays explicit as honest accounting.
|
|
138
|
+
const leadingNative = leading.reduce((sum, u) => sum + u.satoshis, 0n);
|
|
139
|
+
const expectedFee = selection.fee + burnSat + leadingNative;
|
|
140
|
+
(0, index_js_2.assertNativeConservation)(allUtxos, unsignedTx.outs, expectedFee, intent.label);
|
|
141
|
+
// A declared burn tells the fork's absurd-fee-rate cap the intended absolute
|
|
142
|
+
// fee, or build() rejects the (legitimately large) registration burn.
|
|
143
|
+
const maxFeeSats = intent.fee.policy === 'declared' ? expectedFee : undefined;
|
|
144
|
+
const { signedTx, txid } = (0, index_js_2.signTransactionSmart)(unsignedTx.toHex(), intent.wif, allUtxos, verusNetwork, maxFeeSats);
|
|
145
|
+
return {
|
|
146
|
+
signedTx,
|
|
147
|
+
txid,
|
|
148
|
+
fee: selection.fee,
|
|
149
|
+
nativeChange: selection.nativeChange,
|
|
150
|
+
currencyChanges: selection.currencyChanges,
|
|
151
|
+
selected: selection.selected,
|
|
152
|
+
inputsUsed: allUtxos.length,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=assembler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assembler.js","sourceRoot":"","sources":["../../src/assemble/assembler.ts"],"names":[],"mappings":";;AAqFA,0CAsJC;AA3OD;;;;;;;;;;;;;;GAcG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
|
4
|
+
export interface FundedUpdateOutput {
|
|
5
|
+
script: Buffer;
|
|
6
|
+
nativeSat: bigint;
|
|
7
|
+
}
|
|
8
|
+
export interface FundedIdentityUpdateIntent {
|
|
9
|
+
network: Network;
|
|
10
|
+
wif: string;
|
|
11
|
+
expiryHeight: number;
|
|
12
|
+
funding: Utxo[];
|
|
13
|
+
/** The identity UTXO — respent, its definition output recreated at value 0,
|
|
14
|
+
* and re-signed last by the fork. Must carry 0 native (else it burns to fee). */
|
|
15
|
+
identityUtxo: Utxo;
|
|
16
|
+
/** Pre-built outputs (the recreated identity output, plus e.g. a currency
|
|
17
|
+
* definition), emitted before change. Native funding is derived from them. */
|
|
18
|
+
outputs: FundedUpdateOutput[];
|
|
19
|
+
changeAddress: string;
|
|
20
|
+
/** Extra output bytes for fee sizing — the identity/definition scripts are
|
|
21
|
+
* large, so the caller passes their real byte length. */
|
|
22
|
+
extraOutputBytes: number;
|
|
23
|
+
/** Label used in conservation error messages. */
|
|
24
|
+
label: string;
|
|
25
|
+
}
|
|
26
|
+
export interface FundedIdentityUpdateResult {
|
|
27
|
+
signedTx: string;
|
|
28
|
+
txid: string;
|
|
29
|
+
fee: bigint;
|
|
30
|
+
nativeChange: bigint;
|
|
31
|
+
selected: Utxo[];
|
|
32
|
+
inputsUsed: number;
|
|
33
|
+
}
|
|
34
|
+
export declare function assembleFundedIdentityUpdate(intent: FundedIdentityUpdateIntent): FundedIdentityUpdateResult;
|
|
35
|
+
//# sourceMappingURL=fundedIdentityUpdate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fundedIdentityUpdate.d.ts","sourceRoot":"","sources":["../../src/assemble/fundedIdentityUpdate.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAI9C,iDAAiD;AACjD,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,IAAI,EAAE,CAAC;IAChB;sFACkF;IAClF,YAAY,EAAE,IAAI,CAAC;IACnB;mFAC+E;IAC/E,OAAO,EAAE,kBAAkB,EAAE,CAAC;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB;8DAC0D;IAC1D,gBAAgB,EAAE,MAAM,CAAC;IACzB,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,0BAA0B;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,IAAI,EAAE,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,0BAA0B,GACjC,0BAA0B,CAqH5B"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assembleFundedIdentityUpdate = assembleFundedIdentityUpdate;
|
|
4
|
+
/**
|
|
5
|
+
* The assembler for identity-input-respending transactions.
|
|
6
|
+
*
|
|
7
|
+
* A distinct shape from the value-output assembler (`assembler.ts`): these flows
|
|
8
|
+
* (identity update / revoke / recover / lock / unlock, and currency definition)
|
|
9
|
+
* respend the identity's own UTXO and RECREATE its definition output, which the
|
|
10
|
+
* fork must re-sign LAST via `completeFundedIdentityUpdate`. So the tx is built
|
|
11
|
+
* with the funding inputs + pre-built outputs, THEN the identity input is grafted
|
|
12
|
+
* on and the whole thing completed — the value-output assembler's leading-input
|
|
13
|
+
* model doesn't fit.
|
|
14
|
+
*
|
|
15
|
+
* Both callers previously hand-rolled this identical dance (select → build →
|
|
16
|
+
* native change → complete → dual-conservation → sign); it lived in two places
|
|
17
|
+
* and drifted. Centralising it here removes the duplication and makes the
|
|
18
|
+
* value-conservation checks postconditions of the one code path.
|
|
19
|
+
*
|
|
20
|
+
* These paths pay only native (fee + any output value) and emit no token change,
|
|
21
|
+
* so a token-bearing funding UTXO would be silently dropped — the token check
|
|
22
|
+
* fails closed if one is selected. Ported flows stay byte-identical to the
|
|
23
|
+
* Phase-0 goldens.
|
|
24
|
+
*/
|
|
25
|
+
const boundary_js_1 = require("../fork/boundary.js");
|
|
26
|
+
const index_js_1 = require("../utxo/index.js");
|
|
27
|
+
const index_js_2 = require("../signing/index.js");
|
|
28
|
+
const index_js_3 = require("../utils/index.js");
|
|
29
|
+
const index_js_4 = require("../constants/index.js");
|
|
30
|
+
const index_js_5 = require("../identity/index.js");
|
|
31
|
+
const brands_js_1 = require("../core/brands.js");
|
|
32
|
+
const errors_js_1 = require("../errors.js");
|
|
33
|
+
const { completeFundedIdentityUpdate } = boundary_js_1.smarttxs;
|
|
34
|
+
function assembleFundedIdentityUpdate(intent) {
|
|
35
|
+
const verusNetwork = (0, index_js_2.getNetwork)(intent.network === 'testnet');
|
|
36
|
+
const systemId = index_js_4.NETWORK_CONFIG[intent.network].chainId;
|
|
37
|
+
const requiredNative = intent.outputs.reduce((sum, o) => sum + o.nativeSat, 0n);
|
|
38
|
+
const selection = (0, index_js_1.selectUtxos)(intent.funding, requiredNative, new Map(), intent.outputs.length, systemId, undefined, true, intent.extraOutputBytes);
|
|
39
|
+
// These paths emit no token-change output, so a token-bearing funding UTXO
|
|
40
|
+
// would be silently dropped; fail closed if one entered (both maps empty ⇒
|
|
41
|
+
// assert no token value is present).
|
|
42
|
+
(0, index_js_1.assertTokenConservation)(selection.selected, new Map(), new Map(), systemId, intent.label);
|
|
43
|
+
const txb = new boundary_js_1.TransactionBuilder(verusNetwork);
|
|
44
|
+
txb.setVersion(4);
|
|
45
|
+
txb.setExpiryHeight((0, index_js_2.resolveExpiryHeight)(intent.expiryHeight));
|
|
46
|
+
txb.setVersionGroupId(index_js_4.VERSION_GROUP_ID);
|
|
47
|
+
for (const utxo of selection.selected) {
|
|
48
|
+
txb.addInput(Buffer.from(utxo.txid, 'hex').reverse(), utxo.outputIndex, 0xffffffff, Buffer.from(utxo.script, 'hex'));
|
|
49
|
+
}
|
|
50
|
+
for (const o of intent.outputs) {
|
|
51
|
+
txb.addOutput(o.script, (0, index_js_3.toSafeNumber)(o.nativeSat));
|
|
52
|
+
}
|
|
53
|
+
if (selection.nativeChange > 0n) {
|
|
54
|
+
// utxo-lib's addOutput only resolves base58 R-addresses; an i-address
|
|
55
|
+
// changeAddress needs the explicit P2ID script or it throws "no matching Script".
|
|
56
|
+
if (intent.changeAddress.startsWith('i')) {
|
|
57
|
+
txb.addOutput((0, index_js_5.identityPaymentScript)((0, brands_js_1.parseIAddress)(intent.changeAddress, 'changeAddress')), (0, index_js_3.toSafeNumber)(selection.nativeChange));
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
txb.addOutput(intent.changeAddress, (0, index_js_3.toSafeNumber)(selection.nativeChange));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const fundedHex = txb.buildIncomplete().toHex();
|
|
64
|
+
const prevOutScripts = selection.selected.map((u) => Buffer.from(u.script, 'hex'));
|
|
65
|
+
const idUtxo = intent.identityUtxo;
|
|
66
|
+
// The identity input is spent and its definition output recreated with value 0,
|
|
67
|
+
// so any native value on idUtxo would be silently burned to miner fee.
|
|
68
|
+
if (idUtxo.satoshis !== 0n) {
|
|
69
|
+
throw new errors_js_1.TransactionBuildError(`identityUtxo carries ${idUtxo.satoshis} native satoshis, which would be burned to miner fee ` +
|
|
70
|
+
`(the recreated identity output is value 0). Spend that value separately before this operation.`);
|
|
71
|
+
}
|
|
72
|
+
// The identity input is grafted on AFTER assertTokenConservation ran over
|
|
73
|
+
// selection.selected, so any token value it carries sits outside conservation
|
|
74
|
+
// accounting entirely and would be silently dropped. Mirrors the value-output
|
|
75
|
+
// assembler's leading-input guard: enforce the assumption this module's doc
|
|
76
|
+
// comment states rather than trusting it.
|
|
77
|
+
let idCurrencyValues;
|
|
78
|
+
try {
|
|
79
|
+
({ currencyValues: idCurrencyValues } = (0, index_js_1.decodeUtxo)(idUtxo, systemId));
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// An identity output is an EVAL_IDENTITY_PRIMARY CC that decodeUtxo does not
|
|
83
|
+
// model as a value-bearing output, so a failed decode is the NORMAL path
|
|
84
|
+
// here. A token-bearing UTXO is a reserve output (eval 8/9), which decodes
|
|
85
|
+
// cleanly and is still caught below.
|
|
86
|
+
idCurrencyValues = new Map();
|
|
87
|
+
}
|
|
88
|
+
for (const [currency, amount] of idCurrencyValues) {
|
|
89
|
+
if (currency !== systemId && amount > 0n) {
|
|
90
|
+
throw new errors_js_1.TransactionBuildError(`${intent.label}: identityUtxo carries ${amount} of ${currency}, which is outside token ` +
|
|
91
|
+
`conservation and would be burned. An identity output must not carry reserve value.`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const completedHex = completeFundedIdentityUpdate(fundedHex, verusNetwork, prevOutScripts, {
|
|
95
|
+
hash: Buffer.from(idUtxo.txid, 'hex').reverse(),
|
|
96
|
+
index: idUtxo.outputIndex,
|
|
97
|
+
sequence: 0xffffffff,
|
|
98
|
+
script: Buffer.from(idUtxo.script, 'hex'),
|
|
99
|
+
});
|
|
100
|
+
const allUtxos = [...selection.selected, idUtxo];
|
|
101
|
+
// The identity input and its recreated output are both value 0, so the
|
|
102
|
+
// assembled native fee must equal selection.fee. Fail loudly on any slip.
|
|
103
|
+
(0, index_js_2.assertNativeConservation)(allUtxos, boundary_js_1.Transaction.fromHex(completedHex, verusNetwork).outs, selection.fee, intent.label);
|
|
104
|
+
const { signedTx, txid } = (0, index_js_2.signTransactionSmart)(completedHex, intent.wif, allUtxos, verusNetwork);
|
|
105
|
+
return {
|
|
106
|
+
signedTx,
|
|
107
|
+
txid,
|
|
108
|
+
fee: selection.fee,
|
|
109
|
+
nativeChange: selection.nativeChange,
|
|
110
|
+
selected: selection.selected,
|
|
111
|
+
inputsUsed: allUtxos.length,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=fundedIdentityUpdate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fundedIdentityUpdate.js","sourceRoot":"","sources":["../../src/assemble/fundedIdentityUpdate.ts"],"names":[],"mappings":";;AAoEA,oEAuHC;AA3LD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qDAAgF;AAChF,+CAAoF;AACpF,kDAAsH;AACtH,gDAAiD;AACjD,oDAAyE;AACzE,mDAA6D;AAC7D,iDAAkD;AAClD,4CAAqD;AAIrD,MAAM,EAAE,4BAA4B,EAAE,GAAG,sBAAQ,CAAC;AAoClD,SAAgB,4BAA4B,CAC1C,MAAkC;IAElC,MAAM,YAAY,GAAG,IAAA,qBAAU,EAAC,MAAM,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC;IAC9D,MAAM,QAAQ,GAAG,yBAAc,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;IAExD,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAEhF,MAAM,SAAS,GAAG,IAAA,sBAAW,EAC3B,MAAM,CAAC,OAAO,EACd,cAAc,EACd,IAAI,GAAG,EAAE,EACT,MAAM,CAAC,OAAO,CAAC,MAAM,EACrB,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,MAAM,CAAC,gBAAgB,CACxB,CAAC;IAEF,2EAA2E;IAC3E,2EAA2E;IAC3E,qCAAqC;IACrC,IAAA,kCAAuB,EA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