@hsuite/smart-engines-cli 3.2.0 → 4.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 (85) hide show
  1. package/README.md +122 -37
  2. package/dist/_lib/attestation.d.ts +14 -5
  3. package/dist/_lib/attestation.d.ts.map +1 -1
  4. package/dist/_lib/attestation.js +27 -7
  5. package/dist/_lib/attestation.js.map +1 -1
  6. package/dist/_lib/baas.d.ts +5 -2
  7. package/dist/_lib/baas.d.ts.map +1 -1
  8. package/dist/_lib/baas.js +4 -9
  9. package/dist/_lib/baas.js.map +1 -1
  10. package/dist/_lib/cluster-convergence.d.ts +1 -1
  11. package/dist/_lib/cluster-convergence.d.ts.map +1 -1
  12. package/dist/_lib/deposit-verification.d.ts.map +1 -1
  13. package/dist/_lib/deposit-verification.js +0 -1
  14. package/dist/_lib/deposit-verification.js.map +1 -1
  15. package/dist/_lib/env.d.ts +2 -7
  16. package/dist/_lib/env.d.ts.map +1 -1
  17. package/dist/_lib/env.js +7 -30
  18. package/dist/_lib/env.js.map +1 -1
  19. package/dist/_lib/owner-signer.d.ts +110 -0
  20. package/dist/_lib/owner-signer.d.ts.map +1 -0
  21. package/dist/_lib/owner-signer.js +477 -0
  22. package/dist/_lib/owner-signer.js.map +1 -0
  23. package/dist/_lib/runtime-env.d.ts +36 -58
  24. package/dist/_lib/runtime-env.d.ts.map +1 -1
  25. package/dist/_lib/runtime-env.js +80 -62
  26. package/dist/_lib/runtime-env.js.map +1 -1
  27. package/dist/_lib/shell-env.d.ts +16 -0
  28. package/dist/_lib/shell-env.d.ts.map +1 -0
  29. package/dist/_lib/shell-env.js +95 -0
  30. package/dist/_lib/shell-env.js.map +1 -0
  31. package/dist/_lib/subscription-client.d.ts +12 -9
  32. package/dist/_lib/subscription-client.d.ts.map +1 -1
  33. package/dist/_lib/subscription-client.js +5 -7
  34. package/dist/_lib/subscription-client.js.map +1 -1
  35. package/dist/_lib/subscription-env.d.ts +1 -5
  36. package/dist/_lib/subscription-env.d.ts.map +1 -1
  37. package/dist/_lib/subscription-env.js +0 -9
  38. package/dist/_lib/subscription-env.js.map +1 -1
  39. package/dist/commands/app-lifecycle.d.ts.map +1 -1
  40. package/dist/commands/app-lifecycle.js +8 -6
  41. package/dist/commands/app-lifecycle.js.map +1 -1
  42. package/dist/commands/ci.d.ts.map +1 -1
  43. package/dist/commands/ci.js +19 -17
  44. package/dist/commands/ci.js.map +1 -1
  45. package/dist/commands/customer-scope.d.ts +5 -2
  46. package/dist/commands/customer-scope.d.ts.map +1 -1
  47. package/dist/commands/customer-scope.js +12 -13
  48. package/dist/commands/customer-scope.js.map +1 -1
  49. package/dist/commands/deploy.d.ts +0 -7
  50. package/dist/commands/deploy.d.ts.map +1 -1
  51. package/dist/commands/deploy.js +26 -33
  52. package/dist/commands/deploy.js.map +1 -1
  53. package/dist/commands/faucet.d.ts +12 -10
  54. package/dist/commands/faucet.d.ts.map +1 -1
  55. package/dist/commands/faucet.js +14 -23
  56. package/dist/commands/faucet.js.map +1 -1
  57. package/dist/commands/init.d.ts.map +1 -1
  58. package/dist/commands/init.js +10 -2
  59. package/dist/commands/init.js.map +1 -1
  60. package/dist/commands/redeploy.d.ts +0 -6
  61. package/dist/commands/redeploy.d.ts.map +1 -1
  62. package/dist/commands/redeploy.js +21 -22
  63. package/dist/commands/redeploy.js.map +1 -1
  64. package/dist/commands/renew.d.ts +2 -1
  65. package/dist/commands/renew.d.ts.map +1 -1
  66. package/dist/commands/renew.js +15 -10
  67. package/dist/commands/renew.js.map +1 -1
  68. package/dist/commands/status.d.ts.map +1 -1
  69. package/dist/commands/status.js +2 -1
  70. package/dist/commands/status.js.map +1 -1
  71. package/dist/commands/subscribe.d.ts +8 -9
  72. package/dist/commands/subscribe.d.ts.map +1 -1
  73. package/dist/commands/subscribe.js +25 -27
  74. package/dist/commands/subscribe.js.map +1 -1
  75. package/dist/commands/topup.d.ts +2 -1
  76. package/dist/commands/topup.d.ts.map +1 -1
  77. package/dist/commands/topup.js +9 -7
  78. package/dist/commands/topup.js.map +1 -1
  79. package/dist/commands/update.d.ts +3 -3
  80. package/dist/commands/update.d.ts.map +1 -1
  81. package/dist/commands/update.js +12 -5
  82. package/dist/commands/update.js.map +1 -1
  83. package/dist/index.js +5 -2
  84. package/dist/index.js.map +1 -1
  85. package/package.json +2 -2
@@ -0,0 +1,110 @@
1
+ import type { EnvMap } from './env';
2
+ export type OwnerSignerSource = 'seed' | 'private-key' | 'external';
3
+ /** What a message is signed for. Passed to an external signer as its one argument. */
4
+ export type SignPurpose = 'login' | 'attestation' | 'retire' | 'intent';
5
+ export declare const SIGN_PURPOSES: readonly SignPurpose[];
6
+ /** Signs a prepared (autofilled) XRPL transaction and returns the `tx_blob`. */
7
+ export type OwnerTxSigner = (tx: Record<string, unknown>) => string;
8
+ export type OwnerSigner = {
9
+ chain: 'xrpl';
10
+ /** The account: always the caller's own `XRPL_ADDRESS`. */
11
+ walletAddress: string;
12
+ publicKey: string;
13
+ source: OwnerSignerSource;
14
+ /**
15
+ * Sign a UTF-8 message; returns the hex signature ripple-keypairs produces over its upper-hex
16
+ * bytes. `purpose` defaults to `login`, so this is directly the SDK's `signFn`.
17
+ */
18
+ signFn: (message: string, purpose?: SignPurpose) => Promise<string>;
19
+ /** Absent for the `external` source: a message signer cannot sign a transaction. */
20
+ signTx?: OwnerTxSigner;
21
+ };
22
+ /** Which source is configured and for which account. Reading it derives no key. */
23
+ export type OwnerSource = {
24
+ source: OwnerSignerSource;
25
+ address: string;
26
+ };
27
+ export type OwnerSignerOpts = {
28
+ /** The process environment `HSUITE_SIGNER` is read from. Defaults to `process.env`. */
29
+ processEnv?: NodeJS.ProcessEnv;
30
+ /**
31
+ * The environment the SHELL gave the CLI, before dotenv added a `.env` to it. The external
32
+ * signer's environment is built from this, never from `processEnv`. Defaults to the snapshot
33
+ * `loadDotenv()` took.
34
+ */
35
+ shellEnv?: NodeJS.ProcessEnv;
36
+ /** The directory an external signer is warned about living under. Defaults to the cwd. */
37
+ cwd?: string;
38
+ /** Where the "about to sign" lines and the signer's own stderr go. Defaults to stderr. */
39
+ notice?: (text: string) => void;
40
+ /** How long an external signer may take, in ms. Defaults to five minutes. */
41
+ signerTimeoutMs?: number;
42
+ };
43
+ /** The environment an external signer runs with: the allowlist, from the shell's environment. */
44
+ export declare function signerChildEnv(shell: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
45
+ /**
46
+ * Make text safe to print next to a signing prompt. Everything shown there comes from somewhere
47
+ * else (the host's challenge, the signer's stderr), and a terminal obeys escape sequences: an
48
+ * `ESC[2K` or a carriage return can erase or overwrite the line that says what is being signed.
49
+ *
50
+ * Removes the C0 and C1 control characters (ESC, CR and BEL among them), DEL, and the Unicode
51
+ * bidirectional and line-separator controls. Keeps the newline; a tab becomes a space. Longer
52
+ * than `max` characters is cut, and says so.
53
+ */
54
+ export declare function sanitizeForTerminal(text: string, max?: number): string;
55
+ /** The default notice sink: stderr, so stdout stays what a command prints. */
56
+ export declare function defaultNotice(text: string): void;
57
+ /**
58
+ * A block of `label: value` lines, each value sanitised, ready for a notice sink. A value with
59
+ * several lines is shown below its label, every line marked, so it cannot pass for another label.
60
+ */
61
+ export declare function noticeBlock(title: string, fields: ReadonlyArray<readonly [string, string]>): string;
62
+ /**
63
+ * A build attestation is signed as a bare 64-hex string (its hash), with no prefix that says
64
+ * what it is. A login challenge, or any other message, of that exact shape could therefore be an
65
+ * attestation hash: signing it would hand whoever supplied it a valid build attestation for the
66
+ * owner's app. Only the `attestation` purpose may sign that shape. Every source goes through
67
+ * this, in {@link resolveOwnerSigner}.
68
+ *
69
+ * @throws when `purpose` is not `attestation` and `message` is 64 hex characters.
70
+ */
71
+ export declare function assertNotAttestationShaped(message: string, purpose: SignPurpose): void;
72
+ export declare const NO_OWNER_SIGNER_MESSAGE: string;
73
+ /**
74
+ * Which owner signing source the env configures, without deriving a key. `undefined` when no
75
+ * source, or no `XRPL_ADDRESS`, is set.
76
+ *
77
+ * @throws when more than one source is configured, or when `HSUITE_SIGNER` is in the env file.
78
+ */
79
+ export declare function findOwnerSource(env: EnvMap, opts?: OwnerSignerOpts): OwnerSource | undefined;
80
+ /** {@link findOwnerSource}, or the "run `hsuite init`" error when nothing is configured. */
81
+ export declare function requireOwnerSource(env: EnvMap, opts?: OwnerSignerOpts): OwnerSource;
82
+ /**
83
+ * Build the owner's signer from the one configured source.
84
+ *
85
+ * @throws when no source or more than one is configured, when a key is malformed, or when the key
86
+ * (or `XRPL_PUBLIC_KEY`) does not belong to `XRPL_ADDRESS`.
87
+ */
88
+ export declare function resolveOwnerSigner(env: EnvMap, opts?: OwnerSignerOpts): Promise<OwnerSigner>;
89
+ /**
90
+ * A memoised {@link resolveOwnerSigner}: nothing is derived until the first call. For commands
91
+ * whose signing steps sit behind test seams or behind work that can fail first.
92
+ */
93
+ export declare function lazyOwnerSigner(env: EnvMap, opts?: OwnerSignerOpts): () => Promise<OwnerSigner>;
94
+ /** The plain `{ chain, walletAddress, publicKey, signFn }` the SDK takes, bound to one purpose. */
95
+ export declare function forPurpose(signer: OwnerSigner, purpose: SignPurpose): {
96
+ chain: 'xrpl';
97
+ walletAddress: string;
98
+ publicKey: string;
99
+ signFn: (message: string) => Promise<string>;
100
+ };
101
+ /**
102
+ * Refuse, before anything is requested or created, a run that will have to sign an XRPL
103
+ * transaction with a source that cannot.
104
+ */
105
+ export declare function assertCanSignTx(owner: OwnerSource, command: string, hint?: string): void;
106
+ /** The signer's transaction signer, or the clear refusal when it has none. */
107
+ export declare function requireTxSigner(signer: OwnerSigner, command: string): OwnerTxSigner;
108
+ /** {@link requireTxSigner} for a signer that has not been resolved yet. */
109
+ export declare function ownerTxSigner(signer: () => Promise<OwnerSigner>, command: string): Promise<OwnerTxSigner>;
110
+ //# sourceMappingURL=owner-signer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"owner-signer.d.ts","sourceRoot":"","sources":["../../src/_lib/owner-signer.ts"],"names":[],"mappings":"AAqCA,OAAO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AE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAC9C,CAOA;AAUD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAExF;AAED,8EAA8E;AAC9E,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,aAAa,CAGnF;AAED,2EAA2E;AAC3E,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,EAClC,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,aAAa,CAAC,CAExB"}
@@ -0,0 +1,477 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.NO_OWNER_SIGNER_MESSAGE = exports.SIGN_PURPOSES = void 0;
37
+ exports.signerChildEnv = signerChildEnv;
38
+ exports.sanitizeForTerminal = sanitizeForTerminal;
39
+ exports.defaultNotice = defaultNotice;
40
+ exports.noticeBlock = noticeBlock;
41
+ exports.assertNotAttestationShaped = assertNotAttestationShaped;
42
+ exports.findOwnerSource = findOwnerSource;
43
+ exports.requireOwnerSource = requireOwnerSource;
44
+ exports.resolveOwnerSigner = resolveOwnerSigner;
45
+ exports.lazyOwnerSigner = lazyOwnerSigner;
46
+ exports.forPurpose = forPurpose;
47
+ exports.assertCanSignTx = assertCanSignTx;
48
+ exports.requireTxSigner = requireTxSigner;
49
+ exports.ownerTxSigner = ownerTxSigner;
50
+ /**
51
+ * The ONE place the CLI gets the app owner's signing identity from.
52
+ *
53
+ * Every authenticated command signs as the developer wallet: the login challenge, the build
54
+ * attestation, the retire proof, the create intents, and (for the paying commands) XRPL
55
+ * transactions. The key can come from exactly one of three sources:
56
+ *
57
+ * - `seed` `XRPL_SEED` in the env file: an XRPL family seed. What `hsuite init` writes.
58
+ * - `private-key` `XRPL_PRIVATE_KEY` in the env file: a raw key (`00…` secp256k1, `ED…` ed25519).
59
+ * For an account that has no family seed, e.g. a BIP-44 key from a recovery phrase.
60
+ * - `external` `HSUITE_SIGNER` in the PROCESS environment: the absolute path of a program that
61
+ * signs a message. The key never enters this process. Message signing only.
62
+ *
63
+ * `XRPL_ADDRESS` is required with each of them. More than one configured source is refused.
64
+ *
65
+ * THE EXTERNAL SIGNER CONTRACT
66
+ * ----------------------------
67
+ * `HSUITE_SIGNER` is honoured from the process environment only: never from the `--env` file and
68
+ * never from a `.env` in the working directory (see `./shell-env`), so a cloned repository cannot
69
+ * plant an executable. The program is run with `execFile` (no shell) and one argument, the purpose
70
+ * (`login | attestation | retire | intent`). The UTF-8 message is written to its stdin. It prints
71
+ * one hex signature, in ripple-keypairs format, to stdout. Its environment is a short allowlist
72
+ * taken from the SHELL's environment ({@link signerChildEnv}): nothing a `.env` file added, and
73
+ * never `XRPL_SEED` or `XRPL_PRIVATE_KEY`. Its working directory is the home directory. The
74
+ * purpose and the message are printed to stderr before it runs, with control characters removed,
75
+ * and the signature is verified against `XRPL_PUBLIC_KEY` before it is used.
76
+ *
77
+ * ONE MESSAGE SHAPE IS RESERVED: 64 hex characters is what a build attestation signs. Only the
78
+ * `attestation` purpose may sign it, whatever the source (see {@link assertNotAttestationShaped}).
79
+ *
80
+ * NOTHING HERE LOGS A KEY, and no error message carries one.
81
+ */
82
+ const child_process_1 = require("child_process");
83
+ const fs_1 = require("fs");
84
+ const os_1 = require("os");
85
+ const path_1 = require("path");
86
+ const smart_engines_sdk_1 = require("@hsuite/smart-engines-sdk");
87
+ const shell_env_1 = require("./shell-env");
88
+ const xrpl_login_signer_1 = require("./xrpl-login-signer");
89
+ exports.SIGN_PURPOSES = ['login', 'attestation', 'retire', 'intent'];
90
+ const SOURCE_ENV = {
91
+ seed: 'XRPL_SEED',
92
+ 'private-key': 'XRPL_PRIVATE_KEY',
93
+ external: 'HSUITE_SIGNER',
94
+ };
95
+ /**
96
+ * The ONLY variables an external signer inherits, each taken from the shell's environment:
97
+ *
98
+ * PATH to find `node`, `gpg`, the keychain tool
99
+ * HOME USER LOGNAME SHELL where the signer's own key store and config live
100
+ * LANG LC_* TZ TERM text and prompts it prints
101
+ * TMPDIR scratch space
102
+ * SSH_AUTH_SOCK a key held by ssh-agent
103
+ * GPG_AGENT_INFO GPG_TTY a key held by gpg-agent, and its pinentry
104
+ * XDG_RUNTIME_DIR the session bus / agent sockets on Linux
105
+ * DISPLAY WAYLAND_DISPLAY a desktop confirmation prompt
106
+ * HSUITE_SIGNER_* the signer's own settings, set by the user in their shell
107
+ *
108
+ * Everything else is withheld, so nothing that makes an interpreter load code is passed on
109
+ * (`NODE_OPTIONS`, `NODE_PATH`, `PYTHONPATH`, `PYTHONSTARTUP`, `BASH_ENV`, `RUBYOPT`,
110
+ * `LD_PRELOAD`, `DYLD_*`), and neither are `XRPL_SEED` and `XRPL_PRIVATE_KEY`.
111
+ */
112
+ const SIGNER_ENV_ALLOWLIST = new Set([
113
+ 'PATH',
114
+ 'HOME',
115
+ 'USER',
116
+ 'LOGNAME',
117
+ 'SHELL',
118
+ 'LANG',
119
+ 'TZ',
120
+ 'TERM',
121
+ 'TMPDIR',
122
+ 'SSH_AUTH_SOCK',
123
+ 'GPG_AGENT_INFO',
124
+ 'GPG_TTY',
125
+ 'XDG_RUNTIME_DIR',
126
+ 'DISPLAY',
127
+ 'WAYLAND_DISPLAY',
128
+ ]);
129
+ const SIGNER_ENV_PREFIXES = ['LC_', 'HSUITE_SIGNER_'];
130
+ /** The environment an external signer runs with: the allowlist, from the shell's environment. */
131
+ function signerChildEnv(shell) {
132
+ const child = {};
133
+ for (const [key, value] of Object.entries(shell)) {
134
+ if (value === undefined)
135
+ continue;
136
+ if (SIGNER_ENV_ALLOWLIST.has(key) || SIGNER_ENV_PREFIXES.some((p) => key.startsWith(p))) {
137
+ child[key] = value;
138
+ }
139
+ }
140
+ return child;
141
+ }
142
+ /** How much text one notice, and one run's relayed stderr, may put on the terminal. */
143
+ const NOTICE_MAX_CHARS = 4096;
144
+ /**
145
+ * Make text safe to print next to a signing prompt. Everything shown there comes from somewhere
146
+ * else (the host's challenge, the signer's stderr), and a terminal obeys escape sequences: an
147
+ * `ESC[2K` or a carriage return can erase or overwrite the line that says what is being signed.
148
+ *
149
+ * Removes the C0 and C1 control characters (ESC, CR and BEL among them), DEL, and the Unicode
150
+ * bidirectional and line-separator controls. Keeps the newline; a tab becomes a space. Longer
151
+ * than `max` characters is cut, and says so.
152
+ */
153
+ function sanitizeForTerminal(text, max = NOTICE_MAX_CHARS) {
154
+ let clean = '';
155
+ for (const char of text) {
156
+ const code = char.codePointAt(0) ?? 0;
157
+ if (code === 0x09)
158
+ clean += ' ';
159
+ else if (code === 0x0a || !isTerminalControl(code))
160
+ clean += char;
161
+ }
162
+ if (clean.length <= max)
163
+ return clean;
164
+ return `${clean.slice(0, max)}… [truncated: ${clean.length - max} more characters]`;
165
+ }
166
+ function isTerminalControl(code) {
167
+ return (code < 0x20 ||
168
+ (code >= 0x7f && code <= 0x9f) ||
169
+ code === 0x200e ||
170
+ code === 0x200f ||
171
+ code === 0x2028 ||
172
+ code === 0x2029 ||
173
+ (code >= 0x202a && code <= 0x202e) ||
174
+ (code >= 0x2066 && code <= 0x2069));
175
+ }
176
+ /** The default notice sink: stderr, so stdout stays what a command prints. */
177
+ function defaultNotice(text) {
178
+ process.stderr.write(text);
179
+ }
180
+ /**
181
+ * A block of `label: value` lines, each value sanitised, ready for a notice sink. A value with
182
+ * several lines is shown below its label, every line marked, so it cannot pass for another label.
183
+ */
184
+ function noticeBlock(title, fields) {
185
+ // `label:` padded to the longest one, then one space: the values line up.
186
+ const width = Math.max(...fields.map(([label]) => label.length)) + 1;
187
+ const lines = ['', ` ${sanitizeForTerminal(title)}`];
188
+ for (const [label, value] of fields) {
189
+ const shown = sanitizeForTerminal(value).split('\n');
190
+ if (shown.length === 1) {
191
+ lines.push(` ${`${label}:`.padEnd(width)} ${shown[0]}`);
192
+ }
193
+ else {
194
+ lines.push(` ${label}:`);
195
+ for (const line of shown)
196
+ lines.push(` | ${line}`);
197
+ }
198
+ }
199
+ lines.push('');
200
+ return lines.join('\n');
201
+ }
202
+ const ATTESTATION_SHAPED = /^[0-9a-fA-F]{64}$/;
203
+ /**
204
+ * A build attestation is signed as a bare 64-hex string (its hash), with no prefix that says
205
+ * what it is. A login challenge, or any other message, of that exact shape could therefore be an
206
+ * attestation hash: signing it would hand whoever supplied it a valid build attestation for the
207
+ * owner's app. Only the `attestation` purpose may sign that shape. Every source goes through
208
+ * this, in {@link resolveOwnerSigner}.
209
+ *
210
+ * @throws when `purpose` is not `attestation` and `message` is 64 hex characters.
211
+ */
212
+ function assertNotAttestationShaped(message, purpose) {
213
+ if (purpose === 'attestation' || !ATTESTATION_SHAPED.test(message))
214
+ return;
215
+ throw new Error(`Refusing to sign for "${purpose}": the message is 64 hex characters, the shape of a build ` +
216
+ 'attestation hash. A signature over it could be replayed as a build attestation for your ' +
217
+ 'app. Nothing was signed.');
218
+ }
219
+ const DEFAULT_SIGNER_TIMEOUT_MS = 5 * 60_000;
220
+ const XRPL_PUBLIC_KEY = /^(ED[0-9A-F]{64}|0[23][0-9A-F]{64})$/;
221
+ exports.NO_OWNER_SIGNER_MESSAGE = 'No owner signing key: XRPL_SEED + XRPL_ADDRESS required (or XRPL_PRIVATE_KEY + XRPL_ADDRESS, ' +
222
+ 'or HSUITE_SIGNER + XRPL_PUBLIC_KEY + XRPL_ADDRESS). Run `hsuite init` to generate a fresh wallet.';
223
+ function set(value) {
224
+ return value !== undefined && value.trim() !== '' ? value.trim() : undefined;
225
+ }
226
+ function upperHex(message) {
227
+ return Buffer.from(message, 'utf-8').toString('hex').toUpperCase();
228
+ }
229
+ /**
230
+ * Which owner signing source the env configures, without deriving a key. `undefined` when no
231
+ * source, or no `XRPL_ADDRESS`, is set.
232
+ *
233
+ * @throws when more than one source is configured, or when `HSUITE_SIGNER` is in the env file.
234
+ */
235
+ function findOwnerSource(env, opts = {}) {
236
+ if (env.get('HSUITE_SIGNER') !== undefined) {
237
+ throw new Error('HSUITE_SIGNER is set in the env file. It names a program to run, so it is read from the ' +
238
+ 'process environment only. Remove it from the file and export it in your shell.');
239
+ }
240
+ const processEnv = opts.processEnv ?? process.env;
241
+ const configured = [];
242
+ if (set(env.get('XRPL_SEED')))
243
+ configured.push('seed');
244
+ if (set(env.get('XRPL_PRIVATE_KEY')))
245
+ configured.push('private-key');
246
+ if (set(processEnv.HSUITE_SIGNER))
247
+ configured.push('external');
248
+ if (configured.length > 1) {
249
+ throw new Error(`More than one owner signing source is configured: ${configured
250
+ .map((s) => SOURCE_ENV[s])
251
+ .join(' and ')}. Configure exactly one.`);
252
+ }
253
+ const address = set(env.get('XRPL_ADDRESS'));
254
+ if (configured.length === 0 || !address)
255
+ return undefined;
256
+ return { source: configured[0], address };
257
+ }
258
+ /** {@link findOwnerSource}, or the "run `hsuite init`" error when nothing is configured. */
259
+ function requireOwnerSource(env, opts = {}) {
260
+ const found = findOwnerSource(env, opts);
261
+ if (!found)
262
+ throw new Error(exports.NO_OWNER_SIGNER_MESSAGE);
263
+ return found;
264
+ }
265
+ /**
266
+ * Build the owner's signer from the one configured source.
267
+ *
268
+ * @throws when no source or more than one is configured, when a key is malformed, or when the key
269
+ * (or `XRPL_PUBLIC_KEY`) does not belong to `XRPL_ADDRESS`.
270
+ */
271
+ async function resolveOwnerSigner(env, opts = {}) {
272
+ const { source, address } = requireOwnerSource(env, opts);
273
+ const signer = source === 'seed'
274
+ ? await seedSigner(address, env.get('XRPL_SEED').trim())
275
+ : source === 'private-key'
276
+ ? privateKeySigner(address, env.get('XRPL_PRIVATE_KEY').trim())
277
+ : await externalSigner(address, env, opts);
278
+ // The one place every signature of every source goes through.
279
+ return {
280
+ ...signer,
281
+ signFn: async (message, purpose = 'login') => {
282
+ assertNotAttestationShaped(message, purpose);
283
+ return signer.signFn(message, purpose);
284
+ },
285
+ };
286
+ }
287
+ /**
288
+ * A memoised {@link resolveOwnerSigner}: nothing is derived until the first call. For commands
289
+ * whose signing steps sit behind test seams or behind work that can fail first.
290
+ */
291
+ function lazyOwnerSigner(env, opts = {}) {
292
+ let once;
293
+ return () => (once ??= resolveOwnerSigner(env, opts));
294
+ }
295
+ /** The plain `{ chain, walletAddress, publicKey, signFn }` the SDK takes, bound to one purpose. */
296
+ function forPurpose(signer, purpose) {
297
+ return {
298
+ chain: signer.chain,
299
+ walletAddress: signer.walletAddress,
300
+ publicKey: signer.publicKey,
301
+ signFn: (message) => signer.signFn(message, purpose),
302
+ };
303
+ }
304
+ function txSigningUnsupported(command, hint) {
305
+ return new Error(`${command}: this command signs an XRPL transaction; an external message signer cannot do ` +
306
+ 'that — sign it in your wallet, or use XRPL_PRIVATE_KEY / XRPL_SEED' +
307
+ (hint ? `. ${hint}` : ''));
308
+ }
309
+ /**
310
+ * Refuse, before anything is requested or created, a run that will have to sign an XRPL
311
+ * transaction with a source that cannot.
312
+ */
313
+ function assertCanSignTx(owner, command, hint) {
314
+ if (owner.source === 'external')
315
+ throw txSigningUnsupported(command, hint);
316
+ }
317
+ /** The signer's transaction signer, or the clear refusal when it has none. */
318
+ function requireTxSigner(signer, command) {
319
+ if (!signer.signTx)
320
+ throw txSigningUnsupported(command);
321
+ return signer.signTx;
322
+ }
323
+ /** {@link requireTxSigner} for a signer that has not been resolved yet. */
324
+ async function ownerTxSigner(signer, command) {
325
+ return requireTxSigner(await signer(), command);
326
+ }
327
+ // ── sources ─────────────────────────────────────────────────────────────────────────────────────
328
+ /** `XRPL_SEED`: the seed's OWN key (#3667), for the caller's own `XRPL_ADDRESS`. */
329
+ async function seedSigner(address, seed) {
330
+ const login = await (0, xrpl_login_signer_1.buildXrplLoginSigner)(address, seed);
331
+ let signTx;
332
+ return {
333
+ chain: 'xrpl',
334
+ walletAddress: address,
335
+ publicKey: login.publicKey,
336
+ source: 'seed',
337
+ signFn: (message) => login.signFn(message),
338
+ signTx: (tx) => (signTx ??= (0, xrpl_login_signer_1.buildXrplTxSigner)(seed))(tx),
339
+ };
340
+ }
341
+ /** `XRPL_PRIVATE_KEY`: a raw key, which must be the master key of `XRPL_ADDRESS`. */
342
+ function privateKeySigner(address, privateKey) {
343
+ // Refuses a malformed key, and a key that is not this account's, without quoting it.
344
+ const key = (0, smart_engines_sdk_1.createXrplKeySigner)({ privateKey, address });
345
+ let signTx;
346
+ const buildSignTx = () => {
347
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
348
+ const { Wallet } = require('xrpl');
349
+ const hex = privateKey.toUpperCase();
350
+ const wallet = new Wallet(key.publicKey, hex.length === 64 ? `00${hex}` : hex);
351
+ return (tx) => wallet.sign(tx).tx_blob;
352
+ };
353
+ return {
354
+ chain: 'xrpl',
355
+ walletAddress: key.walletAddress,
356
+ publicKey: key.publicKey,
357
+ source: 'private-key',
358
+ signFn: async (message) => key.signFn(message),
359
+ signTx: (tx) => (signTx ??= buildSignTx())(tx),
360
+ };
361
+ }
362
+ /** `HSUITE_SIGNER`: a program that signs a message. See the file header for the contract. */
363
+ async function externalSigner(address, env, opts) {
364
+ const processEnv = opts.processEnv ?? process.env;
365
+ const given = processEnv.HSUITE_SIGNER.trim();
366
+ if (!(0, path_1.isAbsolute)(given)) {
367
+ throw new Error('HSUITE_SIGNER must be the absolute path of the signer program');
368
+ }
369
+ // What actually runs: the path with every symlink resolved. A path that does not resolve is
370
+ // kept as given, and fails when it is run.
371
+ const program = realpathOrSelf(given);
372
+ const publicKey = set(env.get('XRPL_PUBLIC_KEY'))?.toUpperCase();
373
+ if (!publicKey || !XRPL_PUBLIC_KEY.test(publicKey)) {
374
+ throw new Error('HSUITE_SIGNER needs XRPL_PUBLIC_KEY in the env file: the hex public key of XRPL_ADDRESS ' +
375
+ '(ED + 64 hex, or 02/03 + 64 hex)');
376
+ }
377
+ const kp = await Promise.resolve().then(() => __importStar(require('ripple-keypairs')));
378
+ if (kp.deriveAddress(publicKey) !== address) {
379
+ throw new Error(`XRPL_PUBLIC_KEY is not the master key of XRPL_ADDRESS ${address}`);
380
+ }
381
+ const notice = opts.notice ?? defaultNotice;
382
+ const timeoutMs = opts.signerTimeoutMs ?? DEFAULT_SIGNER_TIMEOUT_MS;
383
+ const childEnv = signerChildEnv(opts.shellEnv ?? (0, shell_env_1.shellEnvironment)());
384
+ if (isInside(program, realpathOrSelf(opts.cwd ?? process.cwd()))) {
385
+ notice(noticeBlock('warning: the external signer is inside the current directory', [
386
+ ['signer', program],
387
+ ['advice', 'keep the signer program outside any project checkout'],
388
+ ]));
389
+ }
390
+ return {
391
+ chain: 'xrpl',
392
+ walletAddress: address,
393
+ publicKey,
394
+ source: 'external',
395
+ signFn: async (message, purpose = 'login') => {
396
+ // Shown BEFORE the program runs: it is never asked to sign something the user cannot see.
397
+ notice(noticeBlock('asking the external signer to sign', [
398
+ ['signer', program],
399
+ ['purpose', purpose],
400
+ ['account', address],
401
+ ['message', message],
402
+ ]));
403
+ const output = await runSigner(program, purpose, message, childEnv, timeoutMs, notice);
404
+ const signature = output.trim();
405
+ if (!/^[0-9A-Fa-f]+$/.test(signature)) {
406
+ throw new Error(`external signer (${purpose}): expected one hex signature on stdout, got ` +
407
+ (signature === '' ? 'nothing' : 'something else'));
408
+ }
409
+ let valid = false;
410
+ try {
411
+ valid = kp.verify(upperHex(message), signature.toUpperCase(), publicKey);
412
+ }
413
+ catch {
414
+ valid = false;
415
+ }
416
+ if (!valid) {
417
+ throw new Error(`external signer (${purpose}): the signature does not verify for XRPL_PUBLIC_KEY. ` +
418
+ 'It must be a ripple-keypairs signature of the message, made with the master key of ' +
419
+ `${address}. Nothing was sent.`);
420
+ }
421
+ return signature.toUpperCase();
422
+ },
423
+ };
424
+ }
425
+ function realpathOrSelf(path) {
426
+ try {
427
+ return (0, fs_1.realpathSync)(path);
428
+ }
429
+ catch {
430
+ return path;
431
+ }
432
+ }
433
+ function isInside(file, dir) {
434
+ const rel = (0, path_1.relative)(dir, file);
435
+ return rel !== '' && !rel.startsWith('..') && !(0, path_1.isAbsolute)(rel);
436
+ }
437
+ /**
438
+ * Run the signer: `execFile`, no shell, the message on stdin, the allowlisted environment, the
439
+ * home directory as its working directory (never the project the CLI was started in).
440
+ */
441
+ function runSigner(program, purpose, message, childEnv, timeoutMs, notice) {
442
+ return new Promise((resolve, reject) => {
443
+ let relayed = 0;
444
+ const child = (0, child_process_1.execFile)(program, [purpose], {
445
+ env: childEnv,
446
+ cwd: (0, os_1.homedir)(),
447
+ timeout: timeoutMs,
448
+ maxBuffer: 64 * 1024,
449
+ windowsHide: true,
450
+ }, (err, stdout) => {
451
+ if (!err) {
452
+ resolve(String(stdout));
453
+ return;
454
+ }
455
+ const failure = err;
456
+ const why = failure.killed
457
+ ? `did not answer within ${Math.round(timeoutMs / 1000)}s`
458
+ : typeof failure.code === 'number'
459
+ ? `exited with code ${failure.code}`
460
+ : `could not be run (${failure.code ?? 'unknown error'})`;
461
+ reject(new Error(`external signer (${purpose}) ${why}. Nothing was signed.`));
462
+ });
463
+ // The signer's own prompts ("confirm on your device") reach the user as they are written,
464
+ // minus control characters, and up to a cap: its stderr is not trusted with the terminal.
465
+ child.stderr?.on('data', (chunk) => {
466
+ if (relayed >= NOTICE_MAX_CHARS)
467
+ return;
468
+ const text = sanitizeForTerminal(String(chunk), NOTICE_MAX_CHARS - relayed);
469
+ relayed += text.length;
470
+ notice(text);
471
+ });
472
+ // A signer that exits without reading stdin closes the pipe; the exit code is the error.
473
+ child.stdin?.on('error', () => undefined);
474
+ child.stdin?.end(message, 'utf-8');
475
+ });
476
+ }
477
+ //# sourceMappingURL=owner-signer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"owner-signer.js","sourceRoot":"","sources":["../../src/_lib/owner-signer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoIA,wCASC;AAcD,kDASC;AAgBD,sCAEC;AAMD,kCAkBC;AAaD,gEAOC;AAuBD,0CAsBC;AAGD,gDAIC;AAQD,gDAmBC;AAMD,0CAMC;AAGD,gCAeC;AAcD,0CAEC;AAGD,0CAGC;AAGD,sCAKC;AA7WD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,iDAAyC;AACzC,2BAAkC;AAClC,2BAA6B;AAC7B,+BAA4C;AAC5C,iEAAgE;AAEhE,2CAA+C;AAC/C,2DAA8E;AAOjE,QAAA,aAAa,GAA2B,CAAC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AA2ClG,MAAM,UAAU,GAAsC;IACpD,IAAI,EAAE,WAAW;IACjB,aAAa,EAAE,kBAAkB;IACjC,QAAQ,EAAE,eAAe;CAC1B,CAAC;AAEF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