@usearete/automations 0.0.0-stage → 0.44.1

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.
@@ -0,0 +1,70 @@
1
+ import { ProtocolTransactionFormat, ExecutionIntentV1, ProtocolPreparedTransaction } from '@usearete/sdk';
2
+
3
+ /**
4
+ * What a signer is given. Hand it copies and keep your own snapshot of the
5
+ * prepared transactions for `checkSignedTransactions`: `readonly` is not
6
+ * enforced at run time, and a signer that changed the objects it was given
7
+ * could change a shared baseline too. The runtime does this.
8
+ */
9
+ interface SignTransactionsInput {
10
+ /** The wallet whose signature slot to fill. */
11
+ readonly wallet: string;
12
+ /** What the prepare committed to. */
13
+ readonly intent: ExecutionIntentV1;
14
+ /** The prepared transactions, base64 wire bytes, in intent order. */
15
+ readonly transactions: readonly ProtocolPreparedTransaction[];
16
+ }
17
+ /**
18
+ * Signs prepared protocol transactions for a wallet the backend controls by
19
+ * delegation (a dev keypair, an embedded-wallet provider, a KMS).
20
+ *
21
+ * A signer fills the wallet's signature slot of each transaction and
22
+ * nothing else: it must not change the message, add instructions, touch
23
+ * other signatures, or broadcast. The runtime does not trust this: it
24
+ * re-hashes every returned message against the intent and verifies the
25
+ * wallet's signature before anything is submitted.
26
+ */
27
+ interface ProtocolSigner {
28
+ /** A short name for logs and refusals, for example `keypair` or `privy`. */
29
+ readonly kind: string;
30
+ /** Formats the signer can sign, in order of preference. */
31
+ readonly supportedTransactionFormats: readonly ProtocolTransactionFormat[];
32
+ /** Whether this signer can sign for `wallet` now. */
33
+ canSign(wallet: string): Promise<boolean>;
34
+ /** The signed transactions, base64 wire bytes, one per input in the same order. */
35
+ signTransactions(input: SignTransactionsInput): Promise<string[]>;
36
+ /**
37
+ * Whether the backend holds delegated access to `wallet`, and whether a
38
+ * provider-side policy bounds what it may sign. Granting consent warns
39
+ * when either is missing.
40
+ */
41
+ delegationStatus?(wallet: string): Promise<DelegationStatus>;
42
+ }
43
+ interface DelegationStatus {
44
+ readonly delegated: boolean;
45
+ readonly providerPolicy: boolean;
46
+ readonly detail?: string;
47
+ }
48
+
49
+ /**
50
+ * A signer over a local ed25519 keypair, for development, tests and dev
51
+ * wallets. Production automations sign through a provider whose own policy
52
+ * bounds what the key may sign.
53
+ */
54
+
55
+ interface KeypairSignerOptions {
56
+ /** Formats to offer. Defaults to both. */
57
+ readonly transactionFormats?: readonly ProtocolTransactionFormat[];
58
+ }
59
+ /**
60
+ * A {@link ProtocolSigner} for one keypair: a Solana CLI secret key (64
61
+ * bytes, the seed then the public key, or the JSON array of them) or a
62
+ * 32-byte seed. The key is held only for signing; it never appears in
63
+ * errors or in the signer's properties.
64
+ */
65
+ declare function keypairSigner(secretKey: Uint8Array | readonly number[], options?: KeypairSignerOptions): ProtocolSigner & {
66
+ readonly publicKey: string;
67
+ };
68
+
69
+ export { keypairSigner };
70
+ export type { KeypairSignerOptions };
@@ -0,0 +1,265 @@
1
+ import { ed25519 } from '@noble/curves/ed25519';
2
+ import { base58, base64 } from '@scure/base';
3
+
4
+ function encodeBase58(bytes) {
5
+ return base58.encode(bytes);
6
+ }
7
+ function encodeBase64(bytes) {
8
+ return base64.encode(bytes);
9
+ }
10
+ /** The bytes of a padded base64 string, or `null` when it is not base64. */
11
+ function decodeBase64(text) {
12
+ try {
13
+ return base64.decode(text);
14
+ }
15
+ catch {
16
+ return null;
17
+ }
18
+ }
19
+
20
+ class TransactionDecodeError extends Error {
21
+ constructor(message) {
22
+ super(message);
23
+ this.name = 'TransactionDecodeError';
24
+ }
25
+ }
26
+ /** The version byte of a v1 transaction, which leads its wire bytes. */
27
+ const V1_PREFIX = 0x81;
28
+ /** Configuration mask bits a v1 message may set; each adds one 4-byte value. */
29
+ const V1_KNOWN_CONFIG_BITS = 0b11111;
30
+ class Reader {
31
+ bytes;
32
+ at;
33
+ constructor(bytes, at = 0) {
34
+ this.bytes = bytes;
35
+ this.at = at;
36
+ }
37
+ compactU16() {
38
+ let value = 0;
39
+ for (let index = 0; index < 3; index++) {
40
+ const byte = this.bytes[this.at];
41
+ if (byte === undefined)
42
+ throw new TransactionDecodeError('truncated transaction');
43
+ this.at += 1;
44
+ value |= (byte & 0x7f) << (7 * index);
45
+ if ((byte & 0x80) === 0)
46
+ return value;
47
+ }
48
+ throw new TransactionDecodeError('invalid compact-u16 length');
49
+ }
50
+ take(length) {
51
+ if (this.at + length > this.bytes.length) {
52
+ throw new TransactionDecodeError('truncated transaction');
53
+ }
54
+ const slice = this.bytes.subarray(this.at, this.at + length);
55
+ this.at += length;
56
+ return slice;
57
+ }
58
+ byte() {
59
+ return this.take(1)[0];
60
+ }
61
+ }
62
+ function writableIndexes(keyCount, required, readonlySigned, readonlyUnsigned) {
63
+ if (required > keyCount || readonlySigned > required || readonlyUnsigned > keyCount - required) {
64
+ throw new TransactionDecodeError('invalid message header');
65
+ }
66
+ const out = [];
67
+ for (let index = 0; index < keyCount; index++) {
68
+ const writable = index < required ? index < required - readonlySigned : index < keyCount - readonlyUnsigned;
69
+ if (writable)
70
+ out.push(index);
71
+ }
72
+ return out;
73
+ }
74
+ /** Decode a legacy, v0 or v1 wire transaction. */
75
+ function decodeTransaction(bytes) {
76
+ if (bytes[0] === V1_PREFIX)
77
+ return decodeV1(bytes);
78
+ const reader = new Reader(bytes);
79
+ const signatureCount = reader.compactU16();
80
+ const signatureOffset = reader.at;
81
+ const signatures = [];
82
+ for (let index = 0; index < signatureCount; index++) {
83
+ signatures.push(reader.take(64));
84
+ }
85
+ const messageStart = reader.at;
86
+ const first = bytes[reader.at];
87
+ if (first === undefined)
88
+ throw new TransactionDecodeError('truncated message');
89
+ let version = null;
90
+ if ((first & 0x80) !== 0) {
91
+ reader.at += 1;
92
+ if ((first & 0x7f) !== 0)
93
+ throw new TransactionDecodeError('unsupported transaction version');
94
+ version = 0;
95
+ }
96
+ const header = reader.take(3);
97
+ const [required, readonlySigned, readonlyUnsigned] = [header[0], header[1], header[2]];
98
+ const keyCount = reader.compactU16();
99
+ const staticKeys = [];
100
+ for (let index = 0; index < keyCount; index++) {
101
+ staticKeys.push(encodeBase58(reader.take(32)));
102
+ }
103
+ const writableStatic = writableIndexes(keyCount, required, readonlySigned, readonlyUnsigned);
104
+ reader.take(32); // recent blockhash
105
+ const instructionCount = reader.compactU16();
106
+ const instructionPrograms = [];
107
+ const instructions = [];
108
+ for (let index = 0; index < instructionCount; index++) {
109
+ const programIndex = reader.byte();
110
+ const accounts = reader.take(reader.compactU16());
111
+ const data = reader.take(reader.compactU16());
112
+ instructions.push({ programIndex, accounts: [...accounts], data: data.slice() });
113
+ const program = staticKeys[programIndex];
114
+ if (program === undefined) {
115
+ throw new TransactionDecodeError("an instruction's program is not a static key");
116
+ }
117
+ instructionPrograms.push(program);
118
+ }
119
+ const lookups = [];
120
+ if (version !== null) {
121
+ const count = reader.compactU16();
122
+ for (let index = 0; index < count; index++) {
123
+ const table = encodeBase58(reader.take(32));
124
+ const writable = [...reader.take(reader.compactU16())];
125
+ const readonly = [...reader.take(reader.compactU16())];
126
+ lookups.push({ table, writable, readonly });
127
+ }
128
+ }
129
+ return {
130
+ version,
131
+ signatures,
132
+ signatureOffset,
133
+ message: { start: messageStart, end: bytes.length },
134
+ requiredSignatures: required,
135
+ staticKeys,
136
+ writableStatic,
137
+ instructionPrograms,
138
+ instructions,
139
+ lookups,
140
+ };
141
+ }
142
+ /** A v1 transaction: the version byte and message, then one signature per required signer. */
143
+ function decodeV1(bytes) {
144
+ const reader = new Reader(bytes, 1);
145
+ const header = reader.take(3);
146
+ const [required, readonlySigned, readonlyUnsigned] = [header[0], header[1], header[2]];
147
+ const maskBytes = reader.take(4);
148
+ const mask = (maskBytes[0] | (maskBytes[1] << 8) | (maskBytes[2] << 16) | (maskBytes[3] << 24)) >>> 0;
149
+ if ((mask & ~V1_KNOWN_CONFIG_BITS) >>> 0 !== 0) {
150
+ throw new TransactionDecodeError('unsupported v1 transaction configuration');
151
+ }
152
+ reader.take(32); // lifetime specifier
153
+ const instructionCount = reader.byte();
154
+ const keyCount = reader.byte();
155
+ const staticKeys = [];
156
+ for (let index = 0; index < keyCount; index++) {
157
+ staticKeys.push(encodeBase58(reader.take(32)));
158
+ }
159
+ reader.take(popcount(mask) * 4);
160
+ const headers = reader.take(instructionCount * 4).slice();
161
+ const instructionPrograms = [];
162
+ const instructions = [];
163
+ for (let offset = 0; offset < headers.length; offset += 4) {
164
+ const programIndex = headers[offset];
165
+ const accountCount = headers[offset + 1];
166
+ const dataLength = headers[offset + 2] | (headers[offset + 3] << 8);
167
+ const accounts = reader.take(accountCount);
168
+ const data = reader.take(dataLength);
169
+ instructions.push({ programIndex, accounts: [...accounts], data: data.slice() });
170
+ const program = staticKeys[programIndex];
171
+ if (program === undefined) {
172
+ throw new TransactionDecodeError("an instruction's program is not an address");
173
+ }
174
+ instructionPrograms.push(program);
175
+ }
176
+ const messageEnd = reader.at;
177
+ const signatures = [];
178
+ for (let index = 0; index < required; index++) {
179
+ signatures.push(reader.take(64));
180
+ }
181
+ if (reader.at !== bytes.length) {
182
+ throw new TransactionDecodeError('trailing bytes after the transaction');
183
+ }
184
+ return {
185
+ version: 1,
186
+ signatures,
187
+ signatureOffset: messageEnd,
188
+ message: { start: 0, end: messageEnd },
189
+ requiredSignatures: required,
190
+ staticKeys,
191
+ writableStatic: writableIndexes(keyCount, required, readonlySigned, readonlyUnsigned),
192
+ instructionPrograms,
193
+ instructions,
194
+ lookups: [],
195
+ };
196
+ }
197
+ function popcount(value) {
198
+ let count = 0;
199
+ for (let bits = value >>> 0; bits !== 0; bits >>>= 1)
200
+ count += bits & 1;
201
+ return count;
202
+ }
203
+
204
+ /**
205
+ * A signer over a local ed25519 keypair, for development, tests and dev
206
+ * wallets. Production automations sign through a provider whose own policy
207
+ * bounds what the key may sign.
208
+ */
209
+ /**
210
+ * A {@link ProtocolSigner} for one keypair: a Solana CLI secret key (64
211
+ * bytes, the seed then the public key, or the JSON array of them) or a
212
+ * 32-byte seed. The key is held only for signing; it never appears in
213
+ * errors or in the signer's properties.
214
+ */
215
+ function keypairSigner(secretKey, options = {}) {
216
+ const bytes = Uint8Array.from(secretKey);
217
+ if (bytes.length !== 64 && bytes.length !== 32) {
218
+ throw new Error('a keypair secret key is 64 bytes (seed and public key) or a 32-byte seed');
219
+ }
220
+ const seed = bytes.slice(0, 32);
221
+ const publicKeyBytes = ed25519.getPublicKey(seed);
222
+ if (bytes.length === 64 && !bytes.subarray(32).every((byte, index) => byte === publicKeyBytes[index])) {
223
+ throw new Error("the keypair's public key does not match its secret key");
224
+ }
225
+ bytes.fill(0);
226
+ const publicKey = encodeBase58(publicKeyBytes);
227
+ return {
228
+ kind: 'keypair',
229
+ publicKey,
230
+ supportedTransactionFormats: options.transactionFormats ?? ['v1', 'v0'],
231
+ async canSign(wallet) {
232
+ return wallet === publicKey;
233
+ },
234
+ async delegationStatus(wallet) {
235
+ return {
236
+ delegated: wallet === publicKey,
237
+ providerPolicy: false,
238
+ detail: 'a local keypair has no provider policy; use it for development only',
239
+ };
240
+ },
241
+ async signTransactions({ wallet, transactions }) {
242
+ if (wallet !== publicKey) {
243
+ throw new Error(`this keypair signs for ${publicKey}, not ${wallet}`);
244
+ }
245
+ return transactions.map(({ index, transactionBase64 }) => {
246
+ const wire = decodeBase64(transactionBase64);
247
+ if (wire === null)
248
+ throw new Error(`prepared transaction ${index} is not base64`);
249
+ const decoded = decodeTransaction(wire);
250
+ const required = Math.min(decoded.requiredSignatures, decoded.signatures.length);
251
+ const slot = decoded.staticKeys.slice(0, required).indexOf(publicKey);
252
+ if (slot < 0) {
253
+ throw new Error(`the wallet ${publicKey} is not a required signer of transaction ${index}`);
254
+ }
255
+ const signature = ed25519.sign(wire.subarray(decoded.message.start, decoded.message.end), seed);
256
+ const signed = wire.slice();
257
+ signed.set(signature, decoded.signatureOffset + 64 * slot);
258
+ return encodeBase64(signed);
259
+ });
260
+ },
261
+ };
262
+ }
263
+
264
+ export { keypairSigner };
265
+ //# sourceMappingURL=keypair.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keypair.js","sources":["../src/policy/encoding.ts","../src/policy/decode.ts","../src/keypair.ts"],"sourcesContent":[null,null,null],"names":[],"mappings":";;;AAEM,SAAU,YAAY,CAAC,KAAiB,EAAA;AAC5C,IAAA,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAWK,SAAU,YAAY,CAAC,KAAiB,EAAA;AAC5C,IAAA,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED;AACM,SAAU,YAAY,CAAC,IAAY,EAAA;AACvC,IAAA,IAAI;AACF,QAAA,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;KAC5B;AAAC,IAAA,MAAM;AACN,QAAA,OAAO,IAAI,CAAC;KACb;AACH;;ACUM,MAAO,sBAAuB,SAAQ,KAAK,CAAA;AAC/C,IAAA,WAAA,CAAY,OAAe,EAAA;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;AACf,QAAA,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;KACtC;AACF,CAAA;AAED;AACA,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB;AACA,MAAM,oBAAoB,GAAG,OAAO,CAAC;AAErC,MAAM,MAAM,CAAA;AAIC,IAAA,KAAA,CAAA;AAHX,IAAA,EAAE,CAAS;AAEX,IAAA,WAAA,CACW,KAAiB,EAC1B,EAAE,GAAG,CAAC,EAAA;QADG,IAAK,CAAA,KAAA,GAAL,KAAK,CAAY;AAG1B,QAAA,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;KACd;IAED,UAAU,GAAA;QACR,IAAI,KAAK,GAAG,CAAC,CAAC;AACd,QAAA,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE;YACtC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACjC,IAAI,IAAI,KAAK,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