@hsuite/smart-engines-cli 1.9.0 → 2.0.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 (62) hide show
  1. package/README.md +1 -0
  2. package/dist/__tests__/helpers/xrpl-signing.d.ts +26 -0
  3. package/dist/__tests__/helpers/xrpl-signing.d.ts.map +1 -0
  4. package/dist/__tests__/helpers/xrpl-signing.js +39 -0
  5. package/dist/__tests__/helpers/xrpl-signing.js.map +1 -0
  6. package/dist/_lib/env.d.ts.map +1 -1
  7. package/dist/_lib/env.js +9 -7
  8. package/dist/_lib/env.js.map +1 -1
  9. package/dist/_lib/error-message.d.ts +7 -0
  10. package/dist/_lib/error-message.d.ts.map +1 -0
  11. package/dist/_lib/error-message.js +21 -0
  12. package/dist/_lib/error-message.js.map +1 -0
  13. package/dist/_lib/order-deadline.d.ts +23 -0
  14. package/dist/_lib/order-deadline.d.ts.map +1 -1
  15. package/dist/_lib/order-deadline.js +40 -6
  16. package/dist/_lib/order-deadline.js.map +1 -1
  17. package/dist/_lib/payment-guard.d.ts +59 -0
  18. package/dist/_lib/payment-guard.d.ts.map +1 -0
  19. package/dist/_lib/payment-guard.js +188 -0
  20. package/dist/_lib/payment-guard.js.map +1 -0
  21. package/dist/_lib/payment-lock.d.ts +27 -0
  22. package/dist/_lib/payment-lock.d.ts.map +1 -0
  23. package/dist/_lib/payment-lock.js +199 -0
  24. package/dist/_lib/payment-lock.js.map +1 -0
  25. package/dist/_lib/payment-record.d.ts +70 -0
  26. package/dist/_lib/payment-record.d.ts.map +1 -0
  27. package/dist/_lib/payment-record.js +78 -0
  28. package/dist/_lib/payment-record.js.map +1 -0
  29. package/dist/_lib/runtime-env.d.ts.map +1 -1
  30. package/dist/_lib/runtime-env.js +5 -0
  31. package/dist/_lib/runtime-env.js.map +1 -1
  32. package/dist/_lib/subscription-client.d.ts +40 -11
  33. package/dist/_lib/subscription-client.d.ts.map +1 -1
  34. package/dist/_lib/subscription-client.js +9 -0
  35. package/dist/_lib/subscription-client.js.map +1 -1
  36. package/dist/_lib/xrp-payment.d.ts +33 -0
  37. package/dist/_lib/xrp-payment.d.ts.map +1 -0
  38. package/dist/_lib/xrp-payment.js +99 -0
  39. package/dist/_lib/xrp-payment.js.map +1 -0
  40. package/dist/_lib/xrpl-login-signer.d.ts +16 -1
  41. package/dist/_lib/xrpl-login-signer.d.ts.map +1 -1
  42. package/dist/_lib/xrpl-login-signer.js +25 -1
  43. package/dist/_lib/xrpl-login-signer.js.map +1 -1
  44. package/dist/commands/faucet.d.ts +1 -1
  45. package/dist/commands/faucet.d.ts.map +1 -1
  46. package/dist/commands/faucet.js +2 -7
  47. package/dist/commands/faucet.js.map +1 -1
  48. package/dist/commands/subscribe.d.ts +17 -3
  49. package/dist/commands/subscribe.d.ts.map +1 -1
  50. package/dist/commands/subscribe.js +223 -107
  51. package/dist/commands/subscribe.js.map +1 -1
  52. package/dist/commands/topup.d.ts +19 -7
  53. package/dist/commands/topup.d.ts.map +1 -1
  54. package/dist/commands/topup.js +126 -14
  55. package/dist/commands/topup.js.map +1 -1
  56. package/dist/commands/upgrade.d.ts.map +1 -1
  57. package/dist/commands/upgrade.js +15 -4
  58. package/dist/commands/upgrade.js.map +1 -1
  59. package/dist/commands/verify.d.ts.map +1 -1
  60. package/dist/commands/verify.js +7 -1
  61. package/dist/commands/verify.js.map +1 -1
  62. package/package.json +2 -2
package/README.md CHANGED
@@ -11,6 +11,7 @@ npm install -g @hsuite/smart-engines-cli
11
11
  ```
12
12
  hsuite init # XRPL wallet + faucet + .env.local
13
13
  hsuite subscribe --env <file> # paid smart-app subscription on cluster (tier builder|growth|scale|enterprise)
14
+ hsuite subscribe --pay-with xrp # pay the subscription in XRP (quoted at the HST/XRP market; needs XRP payments on)
14
15
 
15
16
  # deployment lifecycle (manifest-driven):
16
17
  hsuite deploy --manifest <f> # THE canonical path — fresh deploy AND redeploy
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Real-seed fixtures for the signing-identity specs (#3667).
3
+ *
4
+ * `xrpl@4.6.0`'s `Wallet.fromSeed(seed)` forces ed25519 whatever algorithm the seed carries, so a
5
+ * spec that only ever signs with an ed25519 seed cannot tell a correct signer from the broken one.
6
+ * Every path under test is therefore driven twice: with a real secp256k1 seed AND a real ed25519 one.
7
+ */
8
+ export type SeedAlgorithm = 'ecdsa-secp256k1' | 'ed25519';
9
+ export declare const SEED_ALGORITHMS: readonly SeedAlgorithm[];
10
+ export type SeedIdentity = {
11
+ algorithm: SeedAlgorithm;
12
+ seed: string;
13
+ /** The key `ripple-keypairs.deriveKeypair(seed)` yields: the seed's OWN algorithm. */
14
+ publicKey: string;
15
+ /** The account that key is the master key of. */
16
+ address: string;
17
+ };
18
+ /** A fresh real seed of the given algorithm and the account it controls. */
19
+ export declare function makeSeedIdentity(algorithm: SeedAlgorithm): SeedIdentity;
20
+ /**
21
+ * Assert a signed tx_blob is signed by the key behind `identity.address`: the tx names that account,
22
+ * its SigningPubKey is the seed's own key (and derives to that account), and the signature verifies.
23
+ * Returns the decoded transaction for further assertions.
24
+ */
25
+ export declare function expectSignedBy(blob: string, identity: SeedIdentity): Record<string, unknown>;
26
+ //# sourceMappingURL=xrpl-signing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xrpl-signing.d.ts","sourceRoot":"","sources":["../../../src/__tests__/helpers/xrpl-signing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,aAAa,GAAG,iBAAiB,GAAG,SAAS,CAAC;AAE1D,eAAO,MAAM,eAAe,EAAE,SAAS,aAAa,EAAmC,CAAC;AAExF,MAAM,MAAM,YAAY,GAAG;IACzB,SAAS,EAAE,aAAa,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,sFAAsF;IACtF,SAAS,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,4EAA4E;AAC5E,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,aAAa,GAAG,YAAY,CAMvE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAW5F"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ /**
3
+ * Real-seed fixtures for the signing-identity specs (#3667).
4
+ *
5
+ * `xrpl@4.6.0`'s `Wallet.fromSeed(seed)` forces ed25519 whatever algorithm the seed carries, so a
6
+ * spec that only ever signs with an ed25519 seed cannot tell a correct signer from the broken one.
7
+ * Every path under test is therefore driven twice: with a real secp256k1 seed AND a real ed25519 one.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.SEED_ALGORITHMS = void 0;
11
+ exports.makeSeedIdentity = makeSeedIdentity;
12
+ exports.expectSignedBy = expectSignedBy;
13
+ exports.SEED_ALGORITHMS = ['ecdsa-secp256k1', 'ed25519'];
14
+ /** A fresh real seed of the given algorithm and the account it controls. */
15
+ function makeSeedIdentity(algorithm) {
16
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
17
+ const { generateSeed, deriveKeypair, deriveAddress } = require('ripple-keypairs');
18
+ const seed = generateSeed({ algorithm });
19
+ const { publicKey } = deriveKeypair(seed);
20
+ return { algorithm, seed, publicKey, address: deriveAddress(publicKey) };
21
+ }
22
+ /**
23
+ * Assert a signed tx_blob is signed by the key behind `identity.address`: the tx names that account,
24
+ * its SigningPubKey is the seed's own key (and derives to that account), and the signature verifies.
25
+ * Returns the decoded transaction for further assertions.
26
+ */
27
+ function expectSignedBy(blob, identity) {
28
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
29
+ const { decode, verifySignature } = require('xrpl');
30
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
31
+ const { deriveAddress } = require('ripple-keypairs');
32
+ const tx = decode(blob);
33
+ expect(tx.Account).toBe(identity.address);
34
+ expect(tx.SigningPubKey).toBe(identity.publicKey);
35
+ expect(deriveAddress(tx.SigningPubKey)).toBe(identity.address);
36
+ expect(verifySignature(blob)).toBe(true);
37
+ return tx;
38
+ }
39
+ //# sourceMappingURL=xrpl-signing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xrpl-signing.js","sourceRoot":"","sources":["../../../src/__tests__/helpers/xrpl-signing.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAgBH,4CAMC;AAOD,wCAWC;AApCY,QAAA,eAAe,GAA6B,CAAC,iBAAiB,EAAE,SAAS,CAAC,CAAC;AAWxF,4EAA4E;AAC5E,SAAgB,gBAAgB,CAAC,SAAwB;IACvD,8DAA8D;IAC9D,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAClF,MAAM,IAAI,GAAW,YAAY,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;IACjD,MAAM,EAAE,SAAS,EAAE,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IAC1C,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC;AAC3E,CAAC;AAED;;;;GAIG;AACH,SAAgB,cAAc,CAAC,IAAY,EAAE,QAAsB;IACjE,8DAA8D;IAC9D,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,8DAA8D;IAC9D,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACrD,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAA4B,CAAC;IACnD,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC1C,MAAM,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAClD,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,aAAuB,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzE,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzC,OAAO,EAAE,CAAC;AACZ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/_lib/env.ts"],"names":[],"mappings":"AA2BA,MAAM,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEzC,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAgB5C;AA4CD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAuB7E;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAYzE;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;CACrC,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAyB1D"}
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/_lib/env.ts"],"names":[],"mappings":"AA0BA,MAAM,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEzC,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAgB5C;AA4CD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAuB7E;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAYzE;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;CACrC,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CA4B1D"}
package/dist/_lib/env.js CHANGED
@@ -17,7 +17,6 @@ exports.buildSignerFromEnv = buildSignerFromEnv;
17
17
  */
18
18
  const crypto_1 = require("crypto");
19
19
  const fs_1 = require("fs");
20
- const xrpl_1 = require("xrpl");
21
20
  function readEnv(path) {
22
21
  if (!(0, fs_1.existsSync)(path))
23
22
  throw new Error(`env file not found: ${path}`);
@@ -135,21 +134,24 @@ function buildSignerFromEnv(env) {
135
134
  if (!seed || !address) {
136
135
  throw new Error('XRPL_SEED + XRPL_ADDRESS required. Run `hsuite init` to generate a fresh wallet.');
137
136
  }
138
- const wallet = xrpl_1.Wallet.fromSeed(seed);
137
+ // The seed's OWN key (#3667): `deriveKeypair(seed)` respects the algorithm the seed carries.
138
+ // `xrpl.Wallet.fromSeed(seed)` forces ed25519, so a secp256k1 seed logged in with a key that
139
+ // does not belong to XRPL_ADDRESS. Same derivation as `buildXrplLoginSigner`.
140
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
141
+ const { deriveKeypair, sign } = require('ripple-keypairs');
142
+ const { publicKey, privateKey } = deriveKeypair(seed);
139
143
  return {
140
144
  chain: 'xrpl',
141
145
  walletAddress: address,
142
- publicKey: wallet.publicKey,
146
+ publicKey,
143
147
  signFn: (message) => {
144
148
  // XRPL Web3 challenge-response: cluster's Web3AuthService verifies via
145
149
  // ripple-keypairs.verify(messageHex.toUpperCase(), signature, publicKey)
146
150
  // — see libs/security-core/src/auth/web3-auth.service.ts:240.
147
151
  // Match that exactly: hex-encode the UTF-8 challenge, uppercase, then
148
- // sign with wallet.privateKey via ripple-keypairs.sign.
149
- // eslint-disable-next-line @typescript-eslint/no-var-requires
150
- const { sign } = require('ripple-keypairs');
152
+ // sign with the derived private key via ripple-keypairs.sign.
151
153
  const messageHex = Buffer.from(message, 'utf-8').toString('hex').toUpperCase();
152
- return sign(messageHex, wallet.privateKey);
154
+ return sign(messageHex, privateKey);
153
155
  },
154
156
  };
155
157
  }
@@ -1 +1 @@
1
- {"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/_lib/env.ts"],"names":[],"mappings":";;AA6BA,0BAgBC;AA4CD,8BAuBC;AAOD,sCAYC;AASD,gDAyBC;AArKD;;;;;;;;;;GAUG;AACH,mCAAqC;AACrC,2BAYY;AACZ,+BAA8B;AAI9B,SAAgB,OAAO,CAAC,IAAY;IAClC,IAAI,CAAC,IAAA,eAAU,EAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,EAAE,CAAC,CAAC;IACtE,MAAM,GAAG,GAAG,IAAI,GAAG,EAAkB,CAAC;IACtC,KAAK,MAAM,GAAG,IAAI,IAAA,iBAAY,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACzD,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;QACxB,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,SAAS;QAC5C,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,EAAE,GAAG,CAAC;YAAE,SAAS;QACrB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE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AK,KAAK,CAAC,MAAM;QAAE,OAAO;IACzC,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AACzC,CAAC;AASD,SAAgB,kBAAkB,CAAC,GAAW;IAC5C,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAClC,MAAM,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACxC,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,kFAAkF,CACnF,CAAC;IACJ,CAAC;IACD,6FAA6F;IAC7F,6FAA6F;IAC7F,8EAA8E;IAC9E,8DAA8D;IAC9D,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC3D,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IACtD,OAAO;QACL,KAAK,EAAE,MAAM;QACb,aAAa,EAAE,OAAO;QACtB,SAAS;QACT,MAAM,EAAE,CAAC,OAAe,EAAE,EAAE;YAC1B,uEAAuE;YACvE,yEAAyE;YACzE,8DAA8D;YAC9D,sEAAsE;YACtE,8DAA8D;YAC9D,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;YAC/E,OAAO,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;QACtC,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A printable reason for whatever was thrown. An `Error` gives its message (its
3
+ * name when the message is empty); a thrown string is itself; anything else is
4
+ * JSON — never "undefined" and never "[object Object]".
5
+ */
6
+ export declare function errorMessage(err: unknown): string;
7
+ //# sourceMappingURL=error-message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-message.d.ts","sourceRoot":"","sources":["../../src/_lib/error-message.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAQjD"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.errorMessage = errorMessage;
4
+ /**
5
+ * A printable reason for whatever was thrown. An `Error` gives its message (its
6
+ * name when the message is empty); a thrown string is itself; anything else is
7
+ * JSON — never "undefined" and never "[object Object]".
8
+ */
9
+ function errorMessage(err) {
10
+ if (err instanceof Error)
11
+ return err.message || err.name;
12
+ if (typeof err === 'string')
13
+ return err;
14
+ try {
15
+ return JSON.stringify(err) ?? String(err);
16
+ }
17
+ catch {
18
+ return String(err);
19
+ }
20
+ }
21
+ //# sourceMappingURL=error-message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-message.js","sourceRoot":"","sources":["../../src/_lib/error-message.ts"],"names":[],"mappings":";;AAKA,oCAQC;AAbD;;;;GAIG;AACH,SAAgB,YAAY,CAAC,GAAY;IACvC,IAAI,GAAG,YAAY,KAAK;QAAE,OAAO,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC;IACzD,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAC;IACxC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;AACH,CAAC"}
@@ -13,6 +13,13 @@ export type OrderQuoteFields = {
13
13
  };
14
14
  priceUsd?: number;
15
15
  hsuiteDue?: string;
16
+ /** #3699 PR2 — an order priced in XRP says what to send here (XRP drops); `amount` stays the HST it ends up as. */
17
+ pay?: {
18
+ asset: string;
19
+ amount: string;
20
+ address: string;
21
+ destinationTag: number;
22
+ };
16
23
  };
17
24
  /**
18
25
  * Print the quote's deadline (local time + minutes remaining) and the
@@ -21,6 +28,22 @@ export type OrderQuoteFields = {
21
28
  * older server) — `expiresAt` is absent in that case, same as today.
22
29
  */
23
30
  export declare function renderOrderDeadline(quote: Pick<OrderQuoteFields, 'expiresAt' | 'rate'>): void;
31
+ /**
32
+ * The Destination Tag line of a quote's payment instructions. The order is matched by the tag, so a
33
+ * payment that omits it (typed by hand, from a wallet whose "destination tag" field was left empty)
34
+ * is not attributed to the order. `!== undefined`, not truthiness: `0` is a valid tag (#3765, #3917).
35
+ */
36
+ export declare function renderDestinationTag(quote: Pick<OrderQuoteFields, 'destinationTag'>): void;
37
+ /**
38
+ * The XUMM deeplink of an XRPL payment instruction. Carries `dt=` whenever the quote has a
39
+ * destination tag (`0` included): a deeplink without it pays an untagged payment, which the
40
+ * platform attributes only to the sole OPEN order on the address (#3917 item 2).
41
+ */
42
+ export declare function xummSendDeeplink(d: Pick<OrderQuoteFields, 'destinationTag'> & {
43
+ walletAddress: string;
44
+ amount: string;
45
+ tokenId: string;
46
+ }): string;
24
47
  /**
25
48
  * Before showing or paying a quote: if its order has already expired, requote
26
49
  * it and return a quote for the NEW amount/tag instead — never put an expired
@@ -1 +1 @@
1
- {"version":3,"file":"order-deadline.d.ts","sourceRoot":"","sources":["../../src/_lib/order-deadline.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE;;sEAEsE;AACtE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;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;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,IAAI,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,GAAG,IAAI,CAG1F;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,CAAC,EAAE,IAAI,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,GAAG;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACvG,MAAM,CAGR;AAED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CAAC,CAAC,SAAS,gBAAgB,EACnE,MAAM,EAAE,IAAI,CAAC,kBAAkB,EAAE,cAAc,CAAC,EAChD,KAAK,EAAE,CAAC,GACP,OAAO,CAAC,CAAC,CAAC,CA2CZ"}
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.renderOrderDeadline = renderOrderDeadline;
7
+ exports.renderDestinationTag = renderDestinationTag;
8
+ exports.xummSendDeeplink = xummSendDeeplink;
7
9
  exports.ensureUnexpiredQuote = ensureUnexpiredQuote;
8
10
  /**
9
11
  * #3699 PR1b-ii, D8 — deadline display + requote-before-pay guard shared by
@@ -19,11 +21,13 @@ exports.ensureUnexpiredQuote = ensureUnexpiredQuote;
19
21
  * inline response for topup) rather than forcing either one into the
20
22
  * other's shape.
21
23
  *
22
- * `hsuite upgrade` does not auto-pay today (manual XUMM / `--no-autopay`
23
- * flow only), so only {@link renderOrderDeadline} applies there — there is
24
- * no auto-pay call site to guard.
24
+ * `hsuite upgrade` does not auto-pay today (manual XUMM flow only), so there is
25
+ * no auto-pay call site to guard — but a manual payer is shown the quote, so it
26
+ * gets the same {@link ensureUnexpiredQuote}, {@link renderDestinationTag} and
27
+ * {@link xummSendDeeplink} (#3917 item 2).
25
28
  */
26
29
  const chalk_1 = __importDefault(require("chalk"));
30
+ const xrp_payment_1 = require("./xrp-payment");
27
31
  /**
28
32
  * Print the quote's deadline (local time + minutes remaining) and the
29
33
  * locked rate source alongside the amount. No-op when the server didn't
@@ -40,6 +44,25 @@ function renderOrderDeadline(quote) {
40
44
  console.log(chalk_1.default.gray(` rate: ${quote.rate.hsuiteUsd} USD/HST (source: ${quote.rate.source})`));
41
45
  }
42
46
  }
47
+ /**
48
+ * The Destination Tag line of a quote's payment instructions. The order is matched by the tag, so a
49
+ * payment that omits it (typed by hand, from a wallet whose "destination tag" field was left empty)
50
+ * is not attributed to the order. `!== undefined`, not truthiness: `0` is a valid tag (#3765, #3917).
51
+ */
52
+ function renderDestinationTag(quote) {
53
+ if (quote.destinationTag === undefined)
54
+ return;
55
+ console.log(chalk_1.default.gray(` tag: ${quote.destinationTag} (Destination Tag — REQUIRED on the payment)`));
56
+ }
57
+ /**
58
+ * The XUMM deeplink of an XRPL payment instruction. Carries `dt=` whenever the quote has a
59
+ * destination tag (`0` included): a deeplink without it pays an untagged payment, which the
60
+ * platform attributes only to the sole OPEN order on the address (#3917 item 2).
61
+ */
62
+ function xummSendDeeplink(d) {
63
+ const tag = d.destinationTag !== undefined ? `&dt=${encodeURIComponent(String(d.destinationTag))}` : '';
64
+ return `xumm://xrpl/send?to=${encodeURIComponent(d.walletAddress)}&amount=${encodeURIComponent(d.amount)}&token=${encodeURIComponent(d.tokenId)}${tag}`;
65
+ }
43
66
  /**
44
67
  * Before showing or paying a quote: if its order has already expired, requote
45
68
  * it and return a quote for the NEW amount/tag instead — never put an expired
@@ -61,9 +84,18 @@ async function ensureUnexpiredQuote(client, quote) {
61
84
  // for the deposit account was already counted in the first quote), so the first deposit's
62
85
  // `baseAmount` / `reserveSurcharge` line items must not survive next to the new amount.
63
86
  const { baseAmount: _base, reserveSurcharge: _surcharge, ...carried } = quote;
87
+ // #3699 PR2 — an XRP order's requote asks the remainder in XRP DROPS (`pay`); `amount` stays the HST the
88
+ // deposit account ends up holding (the requote's re-priced HST target, when it names one).
89
+ const xrp = requoted.pay.asset === 'XRP';
64
90
  const next = {
65
91
  ...carried,
66
- amount: requoted.pay.amount,
92
+ ...(xrp
93
+ ? {
94
+ pay: requoted.pay,
95
+ // Read structurally: this CLI may be built against an SDK that predates `SubscriptionOrder.xrp`.
96
+ amount: requoted.xrp?.hstTarget ?? carried.amount,
97
+ }
98
+ : { amount: requoted.pay.amount }),
67
99
  destinationTag: requoted.pay.destinationTag,
68
100
  orderId: requoted.orderId,
69
101
  expiresAt: requoted.expiresAt,
@@ -71,8 +103,10 @@ async function ensureUnexpiredQuote(client, quote) {
71
103
  priceUsd: requoted.priceUsd,
72
104
  hsuiteDue: requoted.hsuiteDue,
73
105
  };
74
- console.log(chalk_1.default.yellow(` new amount: ${next.amount} HST (tag ${next.destinationTag}), new deadline: ` +
75
- `${next.expiresAt ? new Date(next.expiresAt).toLocaleString() : 'n/a'}\n`));
106
+ const deadline = next.expiresAt ? new Date(next.expiresAt).toLocaleString() : 'n/a';
107
+ console.log(chalk_1.default.yellow(xrp
108
+ ? ` new amount: ${(0, xrp_payment_1.dropsToXrp)(requoted.pay.amount)} XRP (${requoted.pay.amount} drops, tag ${next.destinationTag}), new deadline: ${deadline}\n`
109
+ : ` new amount: ${next.amount} HST (tag ${next.destinationTag}), new deadline: ${deadline}\n`));
76
110
  return next;
77
111
  }
78
112
  //# sourceMappingURL=order-deadline.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"order-deadline.js","sourceRoot":"","sources":["../../src/_lib/order-deadline.ts"],"names":[],"mappings":";;;;;AAwCA,kDAYC;AAYD,oDAmCC;AAnGD;;;;;;;;;;;;;;;;;GAiBG;AACH,kDAA0B;AAgB1B;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,KAAmD;IACrF,IAAI,CAAC,KAAK,CAAC,SAAS;QAAE,OAAO;IAC7B,MAAM,WAAW,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC;IACxD,MAAM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AM,CAAC,SAAS,QAAQ,CAAC,GAAG,CAAC,MAAM,eAAe,IAAI,CAAC,cAAc,oBAAoB,QAAQ,IAAI;QAChJ,CAAC,CAAC,iBAAiB,IAAI,CAAC,MAAM,aAAa,IAAI,CAAC,cAAc,oBAAoB,QAAQ,IAAI,CACjG,CACF,CAAC;IACF,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,59 @@
1
+ import { PENDING_PAYMENT_KEY, PENDING_TOPUP_PAYMENT_KEY, type PendingPayment } from './payment-record';
2
+ /**
3
+ * The env key a flow keeps its record under. One slot per flow: a `topup` must not read a deposit
4
+ * payment `subscribe` could not clear (and the other way round), or an old, credited payment would
5
+ * refuse a new one.
6
+ */
7
+ export type PaymentRecordKey = typeof PENDING_PAYMENT_KEY | typeof PENDING_TOPUP_PAYMENT_KEY;
8
+ /** The one ledger call the lookup needs; the `xrpl` client and every test fake satisfy it. */
9
+ export type LedgerQueryClient = {
10
+ request(req: Record<string, unknown>): Promise<{
11
+ result: any;
12
+ }>;
13
+ };
14
+ /**
15
+ * The payment left this process but no verdict came back (a timeout, a dropped websocket …), or an
16
+ * earlier run's payment may still validate: it may land. A plain "fix the cause and re-run" would
17
+ * invite a second payment, so it gets its own message at each command.
18
+ */
19
+ export declare class PaymentOutcomeUnknownError extends Error {
20
+ constructor(cause: unknown);
21
+ }
22
+ /**
23
+ * The payment an earlier run sent is on the ledger (validated `tesSUCCESS`), but the platform has
24
+ * not credited it. Thrown INSTEAD of paying — whatever the new quote asks.
25
+ */
26
+ export declare class RecordedPaymentLandedError extends Error {
27
+ readonly txHash: string;
28
+ constructor(txHash: string);
29
+ }
30
+ /**
31
+ * The payment record in the env file, whoever's it is, or `undefined` when there is none. An
32
+ * unreadable value is an ERROR, not "none": it could be hiding a payment that landed.
33
+ */
34
+ export declare function readRecordedPayment(envPath: string, key: PaymentRecordKey): PendingPayment | undefined;
35
+ /** The payment an earlier run recorded for `appId`: none when there is no record, or it is another entity's. */
36
+ export declare function readPendingPayment(envPath: string, appId: string, key: PaymentRecordKey): PendingPayment | undefined;
37
+ /**
38
+ * Settle the payment an earlier run recorded BEFORE paying again: ask the ledger what became of THAT
39
+ * transaction. `delivered` refuses ({@link RecordedPaymentLandedError}); `pending` refuses as unknown
40
+ * ({@link PaymentOutcomeUnknownError}); `failed` and `never-landed` mean it delivered nothing and can
41
+ * never deliver, so the run goes on (and its own record replaces this one). FAILS CLOSED: a lookup
42
+ * that errors is an error, never "carry on and pay".
43
+ */
44
+ export declare function refuseIfRecordedPaymentMayLand(client: LedgerQueryClient, envPath: string, appId: string, key: PaymentRecordKey): Promise<void>;
45
+ /**
46
+ * Record the payment about to be submitted. Fails loud — with NOTHING submitted — when the file
47
+ * cannot be written (as the pending create is recorded, #3766): a payment this CLI cannot keep track
48
+ * of is exactly the one a requote or a resumed run would make it pay a second time. The record is
49
+ * single-slot per flow, so writing this one forgets another entity's unfinished record; that is said,
50
+ * not silent.
51
+ */
52
+ export declare function recordPendingPayment(envPath: string, payment: PendingPayment, key: PaymentRecordKey): void;
53
+ /**
54
+ * Forget `appId`'s recorded payment once the platform has CREDITED it. Only that entity's: another
55
+ * entity's record is its own guard. Best effort: a record that survives only makes a later run ask
56
+ * the ledger about a payment that is credited anyway.
57
+ */
58
+ export declare function clearPendingPayment(envPath: string, appId: string, key: PaymentRecordKey): void;
59
+ //# sourceMappingURL=payment-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payment-guard.d.ts","sourceRoot":"","sources":["../../src/_lib/payment-guard.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,mBAAmB,EACnB,yBAAyB,EAIzB,KAAK,cAAc,EAEpB,MAAM,kBAAkB,CAAC;AAE1B;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,mBAAmB,GAAG,OAAO,yBAAyB,CAAC;AAE7F,8FAA8F;AAC9F,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,GAAG,CAAA;KAAE,CAAC,CAAC;CACjE,CAAC;AAEF;;;;GAIG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;gBACvC,KAAK,EAAE,OAAO;CAI3B;AAED;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM;CAIpC;AAkDD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,gBAAgB,GAAG,cAAc,GAAG,SAAS,CAatG;AAED,gHAAgH;AAChH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,gBAAgB,GACpB,cAAc,GAAG,SAAS,CAG5B;AAED;;;;;;GAMG;AACH,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,iBAAiB,EACzB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,gBAAgB,GACpB,OAAO,CAAC,IAAI,CAAC,CAsBf;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,gBAAgB,GAAG,IAAI,CAoB1G;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,gBAAgB,GAAG,IAAI,CAM/F"}
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.RecordedPaymentLandedError = exports.PaymentOutcomeUnknownError = void 0;
7
+ exports.readRecordedPayment = readRecordedPayment;
8
+ exports.readPendingPayment = readPendingPayment;
9
+ exports.refuseIfRecordedPaymentMayLand = refuseIfRecordedPaymentMayLand;
10
+ exports.recordPendingPayment = recordPendingPayment;
11
+ exports.clearPendingPayment = clearPendingPayment;
12
+ /**
13
+ * The I/O half of the recorded-payment guard (#3917 items 3 and 5): the env file that remembers
14
+ * the payment a run SENT, and the ledger lookup that says what became of it. The format and the
15
+ * verdicts are `payment-record.ts`; this module is shared by every command that pays from the
16
+ * developer wallet (`subscribe`, `topup`) so that a resumed run never pays twice.
17
+ *
18
+ * The record is written BEFORE the signed blob leaves the process and kept until the platform has
19
+ * credited the payment. On the next run the ledger is asked about THAT transaction — never about the
20
+ * deposit account's balance, which cannot say whose HST it holds.
21
+ */
22
+ const chalk_1 = __importDefault(require("chalk"));
23
+ const env_1 = require("./env");
24
+ const error_message_1 = require("./error-message");
25
+ const payment_record_1 = require("./payment-record");
26
+ /**
27
+ * The payment left this process but no verdict came back (a timeout, a dropped websocket …), or an
28
+ * earlier run's payment may still validate: it may land. A plain "fix the cause and re-run" would
29
+ * invite a second payment, so it gets its own message at each command.
30
+ */
31
+ class PaymentOutcomeUnknownError extends Error {
32
+ constructor(cause) {
33
+ super((0, error_message_1.errorMessage)(cause), { cause });
34
+ this.name = 'PaymentOutcomeUnknownError';
35
+ }
36
+ }
37
+ exports.PaymentOutcomeUnknownError = PaymentOutcomeUnknownError;
38
+ /**
39
+ * The payment an earlier run sent is on the ledger (validated `tesSUCCESS`), but the platform has
40
+ * not credited it. Thrown INSTEAD of paying — whatever the new quote asks.
41
+ */
42
+ class RecordedPaymentLandedError extends Error {
43
+ txHash;
44
+ constructor(txHash) {
45
+ super(`payment ${txHash}, sent by an earlier run, is on the ledger`);
46
+ this.txHash = txHash;
47
+ this.name = 'RecordedPaymentLandedError';
48
+ }
49
+ }
50
+ exports.RecordedPaymentLandedError = RecordedPaymentLandedError;
51
+ /**
52
+ * The `txnNotFound` answer of a `tx` lookup, in either shape xrpl.js raises it, with the server's
53
+ * `searched_all` (true only when it held every ledger in the range asked for). `undefined` for
54
+ * any other failure.
55
+ */
56
+ function txnNotFoundOf(err) {
57
+ const data = err?.data;
58
+ if (data?.error === 'txnNotFound')
59
+ return { searchedAll: data.searched_all === true };
60
+ if (/txnNotFound/.test(err instanceof Error ? err.message : ''))
61
+ return { searchedAll: false };
62
+ return undefined;
63
+ }
64
+ /**
65
+ * Ask the ledger for a transaction by hash, over `[LastLedgerSequence - 256, LastLedgerSequence]`
66
+ * when the record carries one (the only range the payment can be in). `found: false` is its
67
+ * `txnNotFound`; any other failure throws.
68
+ */
69
+ async function lookupTx(client, payment) {
70
+ const lls = payment.lastLedgerSequence;
71
+ let res;
72
+ try {
73
+ res = await client.request({
74
+ command: 'tx',
75
+ transaction: payment.txHash,
76
+ ...(lls !== undefined ? { min_ledger: Math.max(1, lls - payment_record_1.LLS_HISTORY_WINDOW), max_ledger: lls } : {}),
77
+ });
78
+ }
79
+ catch (err) {
80
+ const notFound = txnNotFoundOf(err);
81
+ if (notFound)
82
+ return { found: false, ...notFound };
83
+ throw err;
84
+ }
85
+ const result = res.result ?? {};
86
+ if (result.error === 'txnNotFound')
87
+ return { found: false, searchedAll: result.searched_all === true };
88
+ if (result.error !== undefined)
89
+ throw new Error(String(result.error));
90
+ return {
91
+ found: true,
92
+ validated: result.validated === true,
93
+ ...(typeof result.meta?.TransactionResult === 'string' ? { result: result.meta.TransactionResult } : {}),
94
+ };
95
+ }
96
+ /** The validated ledger's index, or `undefined` when the ledger does not give a usable one. */
97
+ async function validatedLedgerIndex(client) {
98
+ const res = await client.request({ command: 'ledger', ledger_index: 'validated' });
99
+ const index = Number(res.result?.ledger_index ?? res.result?.ledger?.ledger_index);
100
+ return Number.isFinite(index) ? index : undefined;
101
+ }
102
+ /**
103
+ * The payment record in the env file, whoever's it is, or `undefined` when there is none. An
104
+ * unreadable value is an ERROR, not "none": it could be hiding a payment that landed.
105
+ */
106
+ function readRecordedPayment(envPath, key) {
107
+ const raw = (0, env_1.readEnv)(envPath).get(key);
108
+ if (raw === undefined || raw === '')
109
+ return undefined;
110
+ const parsed = (0, payment_record_1.parsePendingPayment)(raw);
111
+ if (!parsed) {
112
+ throw new Error(`${key} in ${envPath} is not a payment record this CLI wrote (${JSON.stringify(raw)}) — ` +
113
+ 'refusing to pay: it could be hiding a deposit payment that already landed. Check whether ' +
114
+ 'the developer wallet already sent HST to the deposit account; if it did not, delete that ' +
115
+ `${key} line from the file and re-run.`);
116
+ }
117
+ return parsed;
118
+ }
119
+ /** The payment an earlier run recorded for `appId`: none when there is no record, or it is another entity's. */
120
+ function readPendingPayment(envPath, appId, key) {
121
+ const recorded = readRecordedPayment(envPath, key);
122
+ return recorded?.appId === appId ? recorded : undefined;
123
+ }
124
+ /**
125
+ * Settle the payment an earlier run recorded BEFORE paying again: ask the ledger what became of THAT
126
+ * transaction. `delivered` refuses ({@link RecordedPaymentLandedError}); `pending` refuses as unknown
127
+ * ({@link PaymentOutcomeUnknownError}); `failed` and `never-landed` mean it delivered nothing and can
128
+ * never deliver, so the run goes on (and its own record replaces this one). FAILS CLOSED: a lookup
129
+ * that errors is an error, never "carry on and pay".
130
+ */
131
+ async function refuseIfRecordedPaymentMayLand(client, envPath, appId, key) {
132
+ const recorded = readPendingPayment(envPath, appId, key);
133
+ if (!recorded)
134
+ return;
135
+ let verdict;
136
+ try {
137
+ // The validated ledger FIRST: a payment absent from a complete search whose LastLedgerSequence
138
+ // is behind an index read BEFORE the search cannot have validated in between.
139
+ const validated = await validatedLedgerIndex(client);
140
+ verdict = (0, payment_record_1.classifyRecordedPayment)(await lookupTx(client, recorded), recorded, validated);
141
+ }
142
+ catch (err) {
143
+ throw new Error(`could not look up payment ${recorded.txHash}, which an earlier run recorded (${(0, error_message_1.errorMessage)(err)}) — ` +
144
+ 'refusing to pay without knowing it did not land', { cause: err });
145
+ }
146
+ if (verdict === 'delivered')
147
+ throw new RecordedPaymentLandedError(recorded.txHash);
148
+ if (verdict === 'pending') {
149
+ throw new PaymentOutcomeUnknownError(new Error(`payment ${recorded.txHash}, sent by an earlier run, has not settled on the ledger yet`));
150
+ }
151
+ }
152
+ /**
153
+ * Record the payment about to be submitted. Fails loud — with NOTHING submitted — when the file
154
+ * cannot be written (as the pending create is recorded, #3766): a payment this CLI cannot keep track
155
+ * of is exactly the one a requote or a resumed run would make it pay a second time. The record is
156
+ * single-slot per flow, so writing this one forgets another entity's unfinished record; that is said,
157
+ * not silent.
158
+ */
159
+ function recordPendingPayment(envPath, payment, key) {
160
+ try {
161
+ const existing = readRecordedPayment(envPath, key);
162
+ if (existing && existing.appId !== payment.appId) {
163
+ console.log(chalk_1.default.yellow(` warning: replacing the unfinished payment record of smart-app entity ${existing.appId} ` +
164
+ `(tx ${existing.txHash}) — resuming that entity can no longer ask the ledger about it.`));
165
+ }
166
+ (0, env_1.upsertEnv)(envPath, { [key]: (0, payment_record_1.formatPendingPayment)(payment) });
167
+ }
168
+ catch (err) {
169
+ throw new Error(`cannot record deposit payment ${payment.txHash} in ${envPath} (${(0, error_message_1.errorMessage)(err)}) — refusing ` +
170
+ 'to pay: a payment this CLI cannot keep track of could be paid again after a requote or by a resumed run. ' +
171
+ 'Nothing was submitted and nothing has been paid.', { cause: err });
172
+ }
173
+ }
174
+ /**
175
+ * Forget `appId`'s recorded payment once the platform has CREDITED it. Only that entity's: another
176
+ * entity's record is its own guard. Best effort: a record that survives only makes a later run ask
177
+ * the ledger about a payment that is credited anyway.
178
+ */
179
+ function clearPendingPayment(envPath, appId, key) {
180
+ try {
181
+ if (readPendingPayment(envPath, appId, key))
182
+ (0, env_1.removeEnvKeys)(envPath, [key]);
183
+ }
184
+ catch {
185
+ // see above
186
+ }
187
+ }
188
+ //# sourceMappingURL=payment-guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payment-guard.js","sourceRoot":"","sources":["../../src/_lib/payment-guard.ts"],"names":[],"mappings":";;;;;;AA+GA,kDAaC;AAGD,gDAOC;AASD,wEA2BC;AASD,oDAoBC;AAOD,k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AC/D,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,iCAAiC,OAAO,CAAC,MAAM,OAAO,OAAO,KAAK,IAAA,4BAAY,EAAC,GAAG,CAAC,eAAe;YAChG,2GAA2G;YAC3G,kDAAkD,EACpD,EAAE,KAAK,EAAE,GAAG,EAAE,CACf,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,OAAe,EAAE,KAAa,EAAE,GAAqB;IACvF,IAAI,CAAC;QACH,IAAI,kBAAkB,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC;YAAE,IAAA,mBAAa,EAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7E,CAAC;IAAC,MAAM,CAAC;QACP,YAAY;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,27 @@
1
+ /** The lock file is the env file's path plus this. */
2
+ export declare const PAYMENT_LOCK_SUFFIX = ".payment-lock";
3
+ /** Who holds a lock: what the lock file says. */
4
+ export type PaymentLockOwner = {
5
+ pid: number;
6
+ host: string;
7
+ /** The command that took it (`hsuite topup`). */
8
+ command: string;
9
+ /** ISO time it was taken. */
10
+ since: string;
11
+ /** Random per acquisition: lets a holder tell its own lock from one that replaced it. */
12
+ token: string;
13
+ };
14
+ /** Another run holds the payment lock for this env file (or the lock file cannot be read). */
15
+ export declare class PaymentLockHeldError extends Error {
16
+ readonly lockPath: string;
17
+ readonly owner: PaymentLockOwner | undefined;
18
+ constructor(lockPath: string, owner: PaymentLockOwner | undefined, message: string);
19
+ }
20
+ /** The lock path for an env file. Resolved through symlinks, so every spelling of one file shares one lock. */
21
+ export declare function paymentLockPath(envPath: string): string;
22
+ /**
23
+ * Run `fn` holding the payment lock of `envPath`. A second caller on the same env file is refused
24
+ * with {@link PaymentLockHeldError} while `fn` runs — before it reads, asks or pays anything.
25
+ */
26
+ export declare function withPaymentLock<T>(envPath: string, command: string, fn: () => Promise<T>): Promise<T>;
27
+ //# sourceMappingURL=payment-lock.d.ts.map