@cardano-slips/flow 0.1.0 → 0.2.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.
Files changed (58) hide show
  1. package/dist/balance-error.d.ts +48 -0
  2. package/dist/balance-error.d.ts.map +1 -0
  3. package/dist/balance-error.js +45 -0
  4. package/dist/balance-error.js.map +1 -0
  5. package/dist/balance.d.ts +54 -0
  6. package/dist/balance.d.ts.map +1 -0
  7. package/dist/balance.js +175 -0
  8. package/dist/balance.js.map +1 -0
  9. package/dist/cip30.d.ts +10 -0
  10. package/dist/cip30.d.ts.map +1 -1
  11. package/dist/cip30.js +16 -0
  12. package/dist/cip30.js.map +1 -1
  13. package/dist/complete-error.d.ts +50 -0
  14. package/dist/complete-error.d.ts.map +1 -0
  15. package/dist/complete-error.js +47 -0
  16. package/dist/complete-error.js.map +1 -0
  17. package/dist/complete.d.ts +58 -0
  18. package/dist/complete.d.ts.map +1 -0
  19. package/dist/complete.js +108 -0
  20. package/dist/complete.js.map +1 -0
  21. package/dist/index.d.ts +16 -1
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +10 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/resolve.d.ts +11 -0
  26. package/dist/resolve.d.ts.map +1 -0
  27. package/dist/resolve.js +21 -0
  28. package/dist/resolve.js.map +1 -0
  29. package/dist/sign-error.d.ts +62 -0
  30. package/dist/sign-error.d.ts.map +1 -0
  31. package/dist/sign-error.js +42 -0
  32. package/dist/sign-error.js.map +1 -0
  33. package/dist/sign.d.ts +38 -0
  34. package/dist/sign.d.ts.map +1 -0
  35. package/dist/sign.js +79 -0
  36. package/dist/sign.js.map +1 -0
  37. package/dist/tokens.css +48 -99
  38. package/dist/utxo.d.ts +16 -0
  39. package/dist/utxo.d.ts.map +1 -0
  40. package/dist/utxo.js +51 -0
  41. package/dist/utxo.js.map +1 -0
  42. package/dist/witness.d.ts +23 -0
  43. package/dist/witness.d.ts.map +1 -0
  44. package/dist/witness.js +101 -0
  45. package/dist/witness.js.map +1 -0
  46. package/package.json +7 -4
  47. package/src/balance-error.ts +77 -0
  48. package/src/balance.ts +285 -0
  49. package/src/cip30.ts +19 -0
  50. package/src/complete-error.ts +83 -0
  51. package/src/complete.ts +198 -0
  52. package/src/index.ts +26 -1
  53. package/src/resolve.ts +40 -0
  54. package/src/sign-error.ts +89 -0
  55. package/src/sign.ts +118 -0
  56. package/src/tokens.css +48 -99
  57. package/src/utxo.ts +70 -0
  58. package/src/witness.ts +132 -0
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Why an intent did not become a transaction. Every refusal carries a spec
3
+ * error code, because each one is a failure of the exchange the spec describes
4
+ * rather than a state of a browser extension (`wallet-error.ts` is the other
5
+ * half, and deliberately has refusals that carry no code).
6
+ */
7
+ import { type ClientErrorCode } from "@cardano-slips/core";
8
+ export type BalanceRefusal =
9
+ /** `validUntil` has already passed. A fresh POST returns a fresh intent. */
10
+ "IntentExpired"
11
+ /** An address in the intent encodes a different network from the Slip's. */
12
+ | "ForeignAddress"
13
+ /** A certificate or withdrawal needs the wallet's stake credential and the address carries none. */
14
+ | "NoStakeCredential"
15
+ /** The change address the wallet gave is not an address these bytes can be read as. */
16
+ | "UnreadableChangeAddress"
17
+ /** The intent withdraws rewards and nobody said what the reward balance is. */
18
+ | "RewardBalanceUnknown"
19
+ /** The wallet cannot cover the intent, the minimum ADA its outputs require, and the fee. */
20
+ | "InsufficientFunds"
21
+ /** The intent cannot be built into a valid transaction for any other reason. */
22
+ | "CannotBalance";
23
+ /**
24
+ * Exhaustive by type: adding a refusal above without listing it here fails to
25
+ * compile, and `test/balance.test.ts` fails if any of them stops being reachable.
26
+ */
27
+ export declare const balanceRefusals: Readonly<Record<BalanceRefusal, true>>;
28
+ /**
29
+ * A wrong-network address is `MALFORMED_RESPONSE` and not `WRONG_NETWORK`:
30
+ * the latter is a disagreement the person can act on by switching wallets, and
31
+ * an endpoint that sent an address on another chain is not one of those.
32
+ */
33
+ export declare const slipErrorCodeFor: (refusal: BalanceRefusal) => ClientErrorCode;
34
+ declare const BalanceError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
35
+ readonly _tag: "BalanceError";
36
+ } & Readonly<A>;
37
+ /** `cause` keeps what evolution-sdk said, so a build failure stays diagnosable. */
38
+ export declare class BalanceError extends BalanceError_base<{
39
+ readonly refusal: BalanceRefusal;
40
+ readonly detail: string;
41
+ readonly cause?: unknown;
42
+ }> {
43
+ get message(): string;
44
+ get code(): ClientErrorCode;
45
+ }
46
+ export declare const refuse: (refusal: BalanceRefusal, detail: string, cause?: unknown) => BalanceError;
47
+ export {};
48
+ //# sourceMappingURL=balance-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"balance-error.d.ts","sourceRoot":"","sources":["../src/balance-error.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAG1D,MAAM,MAAM,cAAc;AACxB,4EAA4E;AAC1E,eAAe;AACjB,4EAA4E;GAC1E,gBAAgB;AAClB,oGAAoG;GAClG,mBAAmB;AACrB,uFAAuF;GACrF,yBAAyB;AAC3B,+EAA+E;GAC7E,sBAAsB;AACxB,4FAA4F;GAC1F,mBAAmB;AACrB,gFAAgF;GAC9E,eAAe,CAAA;AAEnB;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,IAAI,CAAC,CAQlE,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,SAAS,cAAc,KAAG,eAc1D,CAAA;;;;AAED,mFAAmF;AACnF,qBAAa,YAAa,SAAQ,kBAAiC;IACjE,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAA;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CACzB,CAAC;IACA,IAAa,OAAO,IAAI,MAAM,CAE7B;IAED,IAAI,IAAI,IAAI,eAAe,CAE1B;CACF;AAED,eAAO,MAAM,MAAM,GAAI,SAAS,cAAc,EAAE,QAAQ,MAAM,EAAE,QAAQ,OAAO,KAAG,YACA,CAAA"}
@@ -0,0 +1,45 @@
1
+ import { Data } from "effect";
2
+ /**
3
+ * Exhaustive by type: adding a refusal above without listing it here fails to
4
+ * compile, and `test/balance.test.ts` fails if any of them stops being reachable.
5
+ */
6
+ export const balanceRefusals = {
7
+ IntentExpired: true,
8
+ ForeignAddress: true,
9
+ NoStakeCredential: true,
10
+ UnreadableChangeAddress: true,
11
+ RewardBalanceUnknown: true,
12
+ InsufficientFunds: true,
13
+ CannotBalance: true
14
+ };
15
+ /**
16
+ * A wrong-network address is `MALFORMED_RESPONSE` and not `WRONG_NETWORK`:
17
+ * the latter is a disagreement the person can act on by switching wallets, and
18
+ * an endpoint that sent an address on another chain is not one of those.
19
+ */
20
+ export const slipErrorCodeFor = (refusal) => {
21
+ switch (refusal) {
22
+ case "IntentExpired":
23
+ return "INTENT_EXPIRED";
24
+ case "ForeignAddress":
25
+ return "MALFORMED_RESPONSE";
26
+ case "InsufficientFunds":
27
+ return "INSUFFICIENT_FUNDS";
28
+ case "NoStakeCredential":
29
+ case "UnreadableChangeAddress":
30
+ case "RewardBalanceUnknown":
31
+ case "CannotBalance":
32
+ return "CANNOT_BALANCE";
33
+ }
34
+ };
35
+ /** `cause` keeps what evolution-sdk said, so a build failure stays diagnosable. */
36
+ export class BalanceError extends Data.TaggedError("BalanceError") {
37
+ get message() {
38
+ return this.detail;
39
+ }
40
+ get code() {
41
+ return slipErrorCodeFor(this.refusal);
42
+ }
43
+ }
44
+ export const refuse = (refusal, detail, cause) => new BalanceError({ refusal, detail, ...(cause === undefined ? {} : { cause }) });
45
+ //# sourceMappingURL=balance-error.js.map
@@ -0,0 +1 @@
1
+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,CAAC,EAAE,CAAC,CAAA"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The privacy-preserving heart of Mode A: the endpoint's half-transaction
3
+ * becomes a whole one here, against unspent outputs it never sees (ADR-0002).
4
+ *
5
+ * Every term arrives as an argument — unspent outputs, protocol parameters, the
6
+ * reward balance, the clock — for the same reason the verifier takes its five:
7
+ * a balancer that fetched them could be made slow, made to fail, or made to
8
+ * answer wrongly by whoever answered.
9
+ */
10
+ import { type Intent, type Network } from "@cardano-slips/core";
11
+ import type { ProtocolParameters } from "@cardano-slips/verifier";
12
+ import { type UTxO } from "@evolution-sdk/evolution";
13
+ import { Effect } from "effect";
14
+ import { type BalanceError } from "./balance-error.js";
15
+ import type { CborHex } from "./cip30.js";
16
+ /**
17
+ * The verifier's parameters plus the one bound the builder needs and the gate
18
+ * does not. One vocabulary across both halves: the figures that balance a
19
+ * transaction are the figures it will be judged against.
20
+ */
21
+ export type BalancingParameters = ProtocolParameters & {
22
+ /** `maxTxSize`: the byte ceiling a built transaction must fit under. */
23
+ readonly maxTxSize: number;
24
+ };
25
+ export type BalanceInputs = {
26
+ readonly intent: Intent;
27
+ /** The Slip's network. Every address in the intent is held to it. */
28
+ readonly network: Network;
29
+ /** Bech32, from the connected wallet. Change returns here. */
30
+ readonly changeAddress: string;
31
+ readonly utxos: ReadonlyArray<UTxO.UTxO>;
32
+ readonly parameters: BalancingParameters;
33
+ /**
34
+ * The whole balance of the wallet's own reward account, required when the
35
+ * intent withdraws rewards. The ledger accepts one figure and only one, and
36
+ * no CIP-30 method answers it.
37
+ */
38
+ readonly rewardBalance?: bigint;
39
+ /** Unix milliseconds. Handed in, so an expiry is decided by one clock and not two. */
40
+ readonly now: number;
41
+ };
42
+ export type BalancedTransaction = {
43
+ /** The complete unsigned transaction: what `verifier` decodes and the wallet signs. */
44
+ readonly cbor: CborHex;
45
+ readonly fee: bigint;
46
+ /** The slot the body expires at, for the rebuild path to watch. */
47
+ readonly ttl: bigint;
48
+ };
49
+ /**
50
+ * Builds the transaction, or says why not. Nothing here asks the network
51
+ * anything, and nothing describing what the wallet holds leaves this function.
52
+ */
53
+ export declare const balanceIntent: (inputs: BalanceInputs) => Effect.Effect<BalancedTransaction, BalanceError>;
54
+ //# sourceMappingURL=balance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"balance.d.ts","sourceRoot":"","sources":["../src/balance.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAwC,KAAK,MAAM,EAAE,KAAK,OAAO,EAAe,MAAM,qBAAqB,CAAA;AAClH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,EAWL,KAAK,IAAI,EACV,MAAM,0BAA0B,CAAA;AAMjC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,OAAO,EAAE,KAAK,YAAY,EAAU,MAAM,oBAAoB,CAAA;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,kBAAkB,GAAG;IACrD,wEAAwE;IACxE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAC3B,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,qEAAqE;IACrE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,8DAA8D;IAC9D,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACxC,QAAQ,CAAC,UAAU,EAAE,mBAAmB,CAAA;IACxC;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;IAC/B,sFAAsF;IACtF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,uFAAuF;IACvF,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,mEAAmE;IACnE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CACrB,CAAA;AAwHD;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,QAAQ,aAAa,KAAG,MAAM,CAAC,MAAM,CAAC,mBAAmB,EAAE,YAAY,CA4FjG,CAAA"}
@@ -0,0 +1,175 @@
1
+ /**
2
+ * The privacy-preserving heart of Mode A: the endpoint's half-transaction
3
+ * becomes a whole one here, against unspent outputs it never sees (ADR-0002).
4
+ *
5
+ * Every term arrives as an argument — unspent outputs, protocol parameters, the
6
+ * reward balance, the clock — for the same reason the verifier takes its five:
7
+ * a balancer that fetched them could be made slow, made to fail, or made to
8
+ * answer wrongly by whoever answered.
9
+ */
10
+ import { addressIsOnNetwork } from "@cardano-slips/core";
11
+ import { Address, Assets, DRep, mainnet, PoolKeyHash, preprod, preview, Schema, Transaction } from "@evolution-sdk/evolution";
12
+ import { makeTxBuilder } from "@evolution-sdk/evolution/sdk/builders/TransactionBuilder";
13
+ import { Effect } from "effect";
14
+ import { refuse } from "./balance-error.js";
15
+ const chains = { mainnet, preprod, preview };
16
+ /**
17
+ * The slot mapping comes from the parameters rather than from the chain preset:
18
+ * the client converts `validUntil` to a slot and the gate converts that slot
19
+ * back to a time, and two mappings would put an honest transaction outside its
20
+ * own declared window.
21
+ */
22
+ const slotConfigOf = ({ slots }) => ({
23
+ zeroTime: slots.time,
24
+ zeroSlot: slots.slot,
25
+ slotLength: Number(slots.slotLength)
26
+ });
27
+ const builderParameters = (parameters) => ({
28
+ minFeeCoefficient: parameters.minFeeCoefficient,
29
+ minFeeConstant: parameters.minFeeConstant,
30
+ coinsPerUtxoByte: parameters.coinsPerUtxoByte,
31
+ maxTxSize: parameters.maxTxSize
32
+ });
33
+ /**
34
+ * What the builder reads for a certificate's deposit. The script fields are
35
+ * zeroed rather than guessed: version 1 builds no transaction that spends from
36
+ * a script, so a cost model here would be a figure nothing computes from.
37
+ */
38
+ const depositParameters = (parameters) => ({
39
+ minFeeA: Number(parameters.minFeeCoefficient),
40
+ minFeeB: Number(parameters.minFeeConstant),
41
+ maxTxSize: parameters.maxTxSize,
42
+ maxValSize: 0,
43
+ keyDeposit: parameters.stakeDeposit,
44
+ poolDeposit: parameters.poolDeposit,
45
+ drepDeposit: parameters.drepDeposit,
46
+ govActionDeposit: parameters.governanceActionDeposit,
47
+ priceMem: 0,
48
+ priceStep: 0,
49
+ maxTxExMem: 0n,
50
+ maxTxExSteps: 0n,
51
+ coinsPerUtxoByte: parameters.coinsPerUtxoByte,
52
+ collateralPercentage: 0,
53
+ maxCollateralInputs: 0,
54
+ minFeeRefScriptCostPerByte: 0,
55
+ costModels: { PlutusV1: {}, PlutusV2: {}, PlutusV3: {} }
56
+ });
57
+ const assetsOf = (output) => (output.assets ?? []).reduce((assets, asset) => Assets.addByHex(assets, asset.policyId, asset.assetName, BigInt(asset.quantity)), Assets.fromLovelace(BigInt(output.lovelace)));
58
+ /**
59
+ * `Schema.decodeSync(FromBech32)` and not `DRep.fromBech32`: the SDK's
60
+ * declarations carry that function and the shipped module does not export it,
61
+ * so calling it compiles and throws. The seventh gap of ADR-0004.
62
+ */
63
+ const drepFromBech32 = Schema.decodeSync(DRep.FromBech32);
64
+ const drepOf = (declared) => {
65
+ if (declared.drep === "abstain")
66
+ return DRep.alwaysAbstain();
67
+ if (declared.drep === "noConfidence")
68
+ return DRep.alwaysNoConfidence();
69
+ return drepFromBech32(declared.drep);
70
+ };
71
+ /**
72
+ * The Conway forms throughout. The legacy pair encodes no deposit and no
73
+ * refund, and evolution-sdk's builder therefore leaves both out of the balance —
74
+ * a transaction the ledger rejects, because consumed and produced no longer
75
+ * agree. The stated deposit is the protocol parameter exactly, which is what
76
+ * the ledger charges and what the gate holds it to (ADR-0013).
77
+ */
78
+ const applyCertificate = (builder, declared, stakeCredential) => {
79
+ switch (declared.type) {
80
+ case "stakeRegistration":
81
+ return builder.registerStake({ stakeCredential });
82
+ case "stakeDeregistration":
83
+ return builder.deregisterStake({ stakeCredential });
84
+ case "stakeDelegation":
85
+ return builder.delegateToPool({ stakeCredential, poolKeyHash: PoolKeyHash.fromBech32(declared.poolId) });
86
+ case "voteDelegation":
87
+ return builder.delegateToDRep({ stakeCredential, drep: drepOf(declared) });
88
+ }
89
+ };
90
+ const actsOnStake = (intent) => (intent.certificates ?? []).length > 0 || intent.withdrawRewards === true;
91
+ /** The two sites evolution-sdk reports a shortfall from, neither of which carries a structured cause. */
92
+ const isShortfall = (message) => message.startsWith("Coin selection failed") || message.includes("Insufficient funds to cover");
93
+ const readFailure = (cause) => {
94
+ const message = cause instanceof Error ? cause.message : String(cause);
95
+ return isShortfall(message)
96
+ ? refuse("InsufficientFunds", "This wallet does not hold enough to cover the transaction and its fee.", cause)
97
+ : refuse("CannotBalance", `This intent could not be built into a transaction: ${message}`, cause);
98
+ };
99
+ /**
100
+ * Builds the transaction, or says why not. Nothing here asks the network
101
+ * anything, and nothing describing what the wallet holds leaves this function.
102
+ */
103
+ export const balanceIntent = (inputs) => Effect.gen(function* () {
104
+ const { changeAddress, intent, network, parameters, utxos } = inputs;
105
+ const validUntil = Date.parse(intent.validUntil);
106
+ if (validUntil <= inputs.now) {
107
+ return yield* Effect.fail(refuse("IntentExpired", "This request expired while it was open. Ask for a fresh one."));
108
+ }
109
+ for (const output of intent.outputs ?? []) {
110
+ if (!addressIsOnNetwork(output.address, network)) {
111
+ return yield* Effect.fail(refuse("ForeignAddress", `This Slip is on ${network} and it asks to pay an address on another network.`));
112
+ }
113
+ }
114
+ // Inside the error channel, not thrown past it: the signature promises a
115
+ // `BalanceError` and a defect here would reach a person as a stack trace.
116
+ const change = yield* Effect.try({
117
+ try: () => Address.fromBech32(changeAddress),
118
+ catch: (cause) => refuse("UnreadableChangeAddress", "This wallet's change address could not be read as an address.", cause)
119
+ });
120
+ const credential = change.stakingCredential;
121
+ if (actsOnStake(intent) && credential === undefined) {
122
+ return yield* Effect.fail(refuse("NoStakeCredential", "This action acts on a stake credential and this wallet's address carries none."));
123
+ }
124
+ if (intent.withdrawRewards === true && inputs.rewardBalance === undefined) {
125
+ return yield* Effect.fail(refuse("RewardBalanceUnknown", "The reward balance to withdraw is not known, so this cannot be built."));
126
+ }
127
+ const stake = credential === undefined
128
+ ? null
129
+ : {
130
+ credential,
131
+ certificates: intent.certificates ?? [],
132
+ withdrawal: intent.withdrawRewards === true ? (inputs.rewardBalance ?? 0n) : null
133
+ };
134
+ const built = yield* Effect.tryPromise({
135
+ try: async () => {
136
+ let builder = makeTxBuilder({ chain: chains[network] });
137
+ for (const output of intent.outputs ?? []) {
138
+ // Declared lovelace is a floor: `autoMinUtxo` raises an output that
139
+ // cannot pay for its own bytes, and the difference is shown to the
140
+ // person as the client's own adjustment rather than folded in.
141
+ builder = builder.payToAddress({ address: Address.fromBech32(output.address), assets: assetsOf(output) });
142
+ }
143
+ if (stake !== null) {
144
+ for (const declared of stake.certificates)
145
+ builder = applyCertificate(builder, declared, stake.credential);
146
+ if (stake.withdrawal !== null) {
147
+ builder = builder.withdraw({ stakeCredential: stake.credential, amount: stake.withdrawal });
148
+ }
149
+ }
150
+ // Never after `validUntil`, which is the whole of what the spec fixes here.
151
+ builder = builder.setValidity({ to: BigInt(validUntil) });
152
+ return await builder.build({
153
+ changeAddress: change,
154
+ availableUtxos: utxos,
155
+ protocolParameters: builderParameters(parameters),
156
+ fullProtocolParameters: depositParameters(parameters),
157
+ slotConfig: slotConfigOf(parameters),
158
+ autoMinUtxo: true,
159
+ // Leftover too small to become change would otherwise be paid as fee —
160
+ // lovelace leaving the wallet that nothing on screen accounted for.
161
+ onInsufficientChange: "error"
162
+ });
163
+ },
164
+ catch: readFailure
165
+ });
166
+ const transaction = yield* Effect.tryPromise({ try: () => built.toTransaction(), catch: readFailure });
167
+ const ttl = transaction.body.ttl;
168
+ if (ttl === undefined) {
169
+ // We asked for an interval; a body without one could be submitted after
170
+ // `validUntil`, which is the one thing the spec forbids outright here.
171
+ return yield* Effect.fail(refuse("CannotBalance", "The built transaction carries no expiry, and it must."));
172
+ }
173
+ return { cbor: Transaction.toCBORHex(transaction), fee: transaction.body.fee, ttl };
174
+ });
175
+ //# sourceMappingURL=balance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"balance.js","sourceRoot":"","sources":["../src/balance.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,kBAAkB,EAA4D,MAAM,qBAAqB,CAAA;AAElH,OAAO,EACL,OAAO,EACP,MAAM,EACN,IAAI,EACJ,OAAO,EACP,WAAW,EACX,OAAO,EACP,OAAO,EACP,MAAM,EAEN,WAAW,EAEZ,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACL,aAAa,EAGd,MAAM,0DAA0D,CAAA;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,OAAO,EAAqB,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAuC9D,MAAM,MAAM,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAA;AAE5C;;;;;GAKG;AACH,MAAM,YAAY,GAAG,CAAC,EAAE,KAAK,EAAuB,EAAyB,EAAE,CAAC,CAAC;IAC/E,QAAQ,EAAE,KAAK,CAAC,IAAI;IACpB,QAAQ,EAAE,KAAK,CAAC,IAAI;IACpB,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;CACrC,CAAC,CAAA;AAEF,MAAM,iBAAiB,GAAG,CAAC,UAA+B,EAAqB,EAAE,CAAC,CAAC;IACjF,iBAAiB,EAAE,UAAU,CAAC,iBAAiB;IAC/C,cAAc,EAAE,UAAU,CAAC,cAAc;IACzC,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;IAC7C,SAAS,EAAE,UAAU,CAAC,SAAS;CAChC,CAAC,CAAA;AAEF;;;;GAIG;AACH,MAA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E,WAAW,EAAE,CAAC,CAAA;IAEtG,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,CAAA;IAChC,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACtB,wEAAwE;QACxE,uEAAuE;QACvE,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,uDAAuD,CAAC,CAAC,CAAA;IAC7G,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAA;AACrF,CAAC,CAAC,CAAA"}
package/dist/cip30.d.ts CHANGED
@@ -60,6 +60,16 @@ export type Cip30ApiError = {
60
60
  export declare const apiErrorNames: Readonly<Record<number, string>>;
61
61
  /** `-3` is the person saying no, which is not a fault and must not be shown as one. */
62
62
  export declare const REFUSED = -3;
63
+ /**
64
+ * `TxSignError` and `TxSendError` are `APIError`'s shape on their own
65
+ * numbering, and the numbering is the footgun: a declined signature is `2`
66
+ * here, where `2` in `APIError` is an internal error. They never share a call,
67
+ * so which table applies is decided by the method that rejected.
68
+ */
69
+ export declare const txSignErrorNames: Readonly<Record<number, string>>;
70
+ /** `2` from `signTx`: the person declined in the wallet. */
71
+ export declare const USER_DECLINED = 2;
72
+ export declare const txSendErrorNames: Readonly<Record<number, string>>;
63
73
  /** A wallet rejects with a plain `{ code, info }` object, not an `Error`. */
64
74
  export declare const readApiError: (cause: unknown) => Cip30ApiError | undefined;
65
75
  export declare const describeApiError: (error: Cip30ApiError) => string;
@@ -1 +1 @@
1
- {"version":3,"file":"cip30.d.ts","sourceRoot":"","sources":["../src/cip30.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,sFAAsF;AACtF,MAAM,MAAM,OAAO,GAAG,MAAM,CAAA;AAE5B,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,CAAC,IAA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QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AAE5E,+FAA+F;AAC/F,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAK1D,CAAA;AAED,uFAAuF;AACvF,eAAO,MAAM,OAAO,KAAK,CAAA;AAEzB;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAG7D,CAAA;AAED,4DAA4D;AAC5D,eAAO,MAAM,aAAa,IAAI,CAAA;AAE9B,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAG7D,CAAA;AAED,6EAA6E;AAC7E,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,KAAG,aAAa,GAAG,SAK7D,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,OAAO,aAAa,KAAG,MAIvD,CAAA"}
package/dist/cip30.js CHANGED
@@ -36,6 +36,22 @@ export const apiErrorNames = {
36
36
  };
37
37
  /** `-3` is the person saying no, which is not a fault and must not be shown as one. */
38
38
  export const REFUSED = -3;
39
+ /**
40
+ * `TxSignError` and `TxSendError` are `APIError`'s shape on their own
41
+ * numbering, and the numbering is the footgun: a declined signature is `2`
42
+ * here, where `2` in `APIError` is an internal error. They never share a call,
43
+ * so which table applies is decided by the method that rejected.
44
+ */
45
+ export const txSignErrorNames = {
46
+ 1: "ProofGeneration",
47
+ 2: "UserDeclined"
48
+ };
49
+ /** `2` from `signTx`: the person declined in the wallet. */
50
+ export const USER_DECLINED = 2;
51
+ export const txSendErrorNames = {
52
+ 1: "Refused",
53
+ 2: "Failure"
54
+ };
39
55
  /** A wallet rejects with a plain `{ code, info }` object, not an `Error`. */
40
56
  export const readApiError = (cause) => {
41
57
  if (typeof cause !== "object" || cause === null)
package/dist/cip30.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A;AAED,4DAA4D;AAC5D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAA;AAE9B,MAAM,CAAC,MAAM,gBAAgB,GAAqC;IAChE,CAAC,EAAE,SAAS;IACZ,CAAC,EAAE,SAAS;CACb,CAAA;AAED,6EAA6E;AAC7E,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAc,EAA6B,EAAE;IACxE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,SAAS,CAAA;IACjE,MAAM,SAAS,GAAG,KAAgC,CAAA;IAClD,IAAI,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAA;IACxD,OAAO,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAA;AACjG,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAoB,EAAU,EAAE;IAC/D,MAAM,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACtC,MAAM,KAAK,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;IAC9D,OAAO,KAAK,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,KAAK,KAAK,CAAC,IAAI,EAAE,CAAA;AAC9D,CAAC,CAAA"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Why a Slip did not reach the chain, for the failures that belong to the whole
3
+ * path rather than to building, signing or submitting alone. `Blocked` is the
4
+ * one that matters: it is invariant 3 in the error channel, and there is no
5
+ * field on it that lets anyone past.
6
+ */
7
+ import { type ClientErrorCode } from "@cardano-slips/core";
8
+ import type { Reason } from "@cardano-slips/verifier";
9
+ export type CompletionRefusal =
10
+ /** The wallet reported no unspent outputs, so there is nothing to build from. */
11
+ "NoUtxos"
12
+ /** What `getUtxos` answered is not something these bytes can be read as. */
13
+ | "UnreadableUtxos"
14
+ /** The effects could not be derived from the transaction, or compared with the declaration. */
15
+ | "CannotJudge"
16
+ /** The derived effects disagree with what the endpoint declared. Nothing signs after this. */
17
+ | "Blocked"
18
+ /** The caller could not put the effects in front of a person, so nothing may be signed. */
19
+ | "NotShown"
20
+ /** The funds kept moving, and the transaction has been rebuilt as often as it will be. */
21
+ | "OutOfAttempts";
22
+ /**
23
+ * Exhaustive by type: adding a refusal above without listing it here fails to
24
+ * compile, and `test/complete.test.ts` fails if any of them stops being reachable.
25
+ */
26
+ export declare const completionRefusals: Readonly<Record<CompletionRefusal, true>>;
27
+ export declare const slipErrorCodeFor: (refusal: CompletionRefusal) => ClientErrorCode | undefined;
28
+ declare const CompletionError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
29
+ readonly _tag: "CompletionError";
30
+ } & Readonly<A>;
31
+ /**
32
+ * `reasons` is what the transaction actually does against what was declared,
33
+ * for the block to render. There is no way to carry on from one — a mismatch
34
+ * hard-blocks, with no override, no allowlist and no confirmation.
35
+ */
36
+ export declare class CompletionError extends CompletionError_base<{
37
+ readonly refusal: CompletionRefusal;
38
+ readonly detail: string;
39
+ readonly reasons?: ReadonlyArray<Reason>;
40
+ readonly cause?: unknown;
41
+ }> {
42
+ get message(): string;
43
+ get code(): ClientErrorCode | undefined;
44
+ }
45
+ export declare const refuse: (refusal: CompletionRefusal, detail: string, extra?: {
46
+ readonly reasons?: ReadonlyArray<Reason>;
47
+ readonly cause?: unknown;
48
+ }) => CompletionError;
49
+ export {};
50
+ //# sourceMappingURL=complete-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"complete-error.d.ts","sourceRoot":"","sources":["../src/complete-error.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAGrD,MAAM,MAAM,iBAAiB;AAC3B,iFAAiF;AAC/E,SAAS;AACX,4EAA4E;GAC1E,iBAAiB;AACnB,+FAA+F;GAC7F,aAAa;AACf,8FAA8F;GAC5F,SAAS;AACX,2FAA2F;GACzF,UAAU;AACZ,0FAA0F;GACxF,eAAe,CAAA;AAEnB;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAOxE,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,SAAS,iBAAiB,KAAG,eAAe,GAAG,SAa/E,CAAA;;;;AAED;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,qBAAoC;IACvE,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAA;IACnC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IACxC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CACzB,CAAC;IACA,IAAa,OAAO,IAAI,MAAM,CAE7B;IAED,IAAI,IAAI,IAAI,eAAe,GAAG,SAAS,CAEtC;CACF;AAED,eAAO,MAAM,MAAM,GACjB,SAAS,iBAAiB,EAC1B,QAAQ,MAAM,EACd,QAAO;IAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,KACjF,eAMC,CAAA"}
@@ -0,0 +1,47 @@
1
+ import { Data } from "effect";
2
+ /**
3
+ * Exhaustive by type: adding a refusal above without listing it here fails to
4
+ * compile, and `test/complete.test.ts` fails if any of them stops being reachable.
5
+ */
6
+ export const completionRefusals = {
7
+ NoUtxos: true,
8
+ UnreadableUtxos: true,
9
+ CannotJudge: true,
10
+ Blocked: true,
11
+ NotShown: true,
12
+ OutOfAttempts: true
13
+ };
14
+ export const slipErrorCodeFor = (refusal) => {
15
+ switch (refusal) {
16
+ case "Blocked":
17
+ return "EFFECTS_MISMATCH";
18
+ case "NoUtxos":
19
+ return "INSUFFICIENT_FUNDS";
20
+ case "CannotJudge":
21
+ return "CANNOT_BALANCE";
22
+ case "UnreadableUtxos":
23
+ case "NotShown":
24
+ case "OutOfAttempts":
25
+ return undefined;
26
+ }
27
+ };
28
+ /**
29
+ * `reasons` is what the transaction actually does against what was declared,
30
+ * for the block to render. There is no way to carry on from one — a mismatch
31
+ * hard-blocks, with no override, no allowlist and no confirmation.
32
+ */
33
+ export class CompletionError extends Data.TaggedError("CompletionError") {
34
+ get message() {
35
+ return this.detail;
36
+ }
37
+ get code() {
38
+ return slipErrorCodeFor(this.refusal);
39
+ }
40
+ }
41
+ export const refuse = (refusal, detail, extra = {}) => new CompletionError({
42
+ refusal,
43
+ detail,
44
+ ...(extra.reasons === undefined ? {} : { reasons: extra.reasons }),
45
+ ...(extra.cause === undefined ? {} : { cause: extra.cause })
46
+ });
47
+ //# sourceMappingURL=complete-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"complete-error.js","sourceRoot":"","sources":["../src/complete-error.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAgB7B;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAA8C;IAC3E,OAAO,EAAE,IAAI;IACb,eAAe,EAAE,IAAI;IACrB,WAAW,EAAE,IAAI;IACjB,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE,IAAI;IACd,aAAa,EAAE,IAAI;CACpB,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAA0B,EAA+B,EAAE;IAC1F,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,SAAS;YACZ,OAAO,kBAAkB,CAAA;QAC3B,KAAK,SAAS;YACZ,OAAO,oBAAoB,CAAA;QAC7B,KAAK,aAAa;YAChB,OAAO,gBAAgB,CAAA;QACzB,KAAK,iBAAiB,CAAC;QACvB,KAAK,UAAU,CAAC;QAChB,KAAK,eAAe;YAClB,OAAO,SAAS,CAAA;IACpB,CAAC;AACH,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,OAAO,eAAgB,SAAQ,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAKrE;IACA,IAAa,OAAO;QAClB,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACvC,CAAC;CACF;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,CACpB,OAA0B,EAC1B,MAAc,EACd,QAAgF,EAAE,EACjE,EAAE,CACnB,IAAI,eAAe,CAAC;IAClB,OAAO;IACP,MAAM;IACN,GAAG,CAAC,KAAK,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IAClE,GAAG,CAAC,KAAK,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;CAC7D,CAAC,CAAA"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * The whole path: build against what the wallet holds, judge it with the
3
+ * verifier's own engine, sign, submit. When the funds move underneath, every
4
+ * one of those happens again — a rebuilt transaction is a different transaction,
5
+ * and asking for a signature on it without deriving its effects first would put
6
+ * a person's name on something nobody read.
7
+ */
8
+ import type { Intent, Network } from "@cardano-slips/core";
9
+ import { type Effects } from "@cardano-slips/verifier";
10
+ import { Effect } from "effect";
11
+ import { type BalancingParameters } from "./balance.js";
12
+ import type { BalanceError } from "./balance-error.js";
13
+ import type { Cip30Api } from "./cip30.js";
14
+ import { type CompletionError } from "./complete-error.js";
15
+ import type { SigningError } from "./sign-error.js";
16
+ export type Attempt = {
17
+ /** Counting from one, so a rendered "attempt 2 of 3" reads as a person would say it. */
18
+ readonly number: number;
19
+ readonly transactionId: string;
20
+ /** What this transaction does, derived from its own bytes. */
21
+ readonly effects: Effects;
22
+ };
23
+ export type CompletionRequest = {
24
+ readonly api: Cip30Api;
25
+ /** What the endpoint declared, and what the transaction is judged against. */
26
+ readonly intent: Intent;
27
+ readonly network: Network;
28
+ readonly changeAddress: string;
29
+ /**
30
+ * Every address the wallet calls its own, its reward account included. An
31
+ * address missing from here is read as a stranger's, which turns the wallet's
32
+ * own change into an undeclared payment and blocks the Slip.
33
+ */
34
+ readonly userAddresses: ReadonlyArray<Uint8Array>;
35
+ readonly parameters: BalancingParameters;
36
+ readonly rewardBalance?: bigint;
37
+ /** Read once per attempt: a rebuilt transaction gets its own validity window. */
38
+ readonly now?: () => number;
39
+ /** How many times the transaction may be built. Beyond this the funds are moving faster than we can follow. */
40
+ readonly attempts?: number;
41
+ /** Called once per attempt, after the effects are derived and before the wallet is asked to sign. */
42
+ readonly onAttempt?: (attempt: Attempt) => void;
43
+ };
44
+ export type Receipt = {
45
+ readonly transactionId: string;
46
+ readonly effects: Effects;
47
+ /** How many transactions it took, which is how many times the funds moved plus one. */
48
+ readonly attempts: number;
49
+ };
50
+ type Failure = BalanceError | CompletionError | SigningError;
51
+ /**
52
+ * Completes the Slip, or says why not. A submission that failed because an
53
+ * input was spent is the one failure worth repeating: everything else either
54
+ * cannot be helped by a rebuild or is a person having said no.
55
+ */
56
+ export declare const completeIntent: (request: CompletionRequest) => Effect.Effect<Receipt, Failure>;
57
+ export {};
58
+ //# sourceMappingURL=complete.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"complete.d.ts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