@dexterai/vault 0.1.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 (43) hide show
  1. package/LICENSE +24 -0
  2. package/README.md +61 -0
  3. package/dist/constants/index.cjs +92 -0
  4. package/dist/constants/index.d.cts +34 -0
  5. package/dist/constants/index.d.ts +34 -0
  6. package/dist/constants/index.js +57 -0
  7. package/dist/counterfactual.cjs +138 -0
  8. package/dist/counterfactual.d.cts +17 -0
  9. package/dist/counterfactual.d.ts +17 -0
  10. package/dist/counterfactual.js +113 -0
  11. package/dist/index.cjs +140 -0
  12. package/dist/index.d.cts +2 -0
  13. package/dist/index.d.ts +2 -0
  14. package/dist/index.js +113 -0
  15. package/dist/instructions/index.cjs +5016 -0
  16. package/dist/instructions/index.d.cts +290 -0
  17. package/dist/instructions/index.d.ts +290 -0
  18. package/dist/instructions/index.js +4989 -0
  19. package/dist/messages/index.cjs +156 -0
  20. package/dist/messages/index.d.cts +89 -0
  21. package/dist/messages/index.d.ts +89 -0
  22. package/dist/messages/index.js +125 -0
  23. package/dist/precompile/index.cjs +192 -0
  24. package/dist/precompile/index.d.cts +45 -0
  25. package/dist/precompile/index.d.ts +45 -0
  26. package/dist/precompile/index.js +149 -0
  27. package/dist/reader/index.cjs +121 -0
  28. package/dist/reader/index.d.cts +41 -0
  29. package/dist/reader/index.d.ts +41 -0
  30. package/dist/reader/index.js +93 -0
  31. package/dist/signers/node/index.cjs +62 -0
  32. package/dist/signers/node/index.d.cts +21 -0
  33. package/dist/signers/node/index.d.ts +21 -0
  34. package/dist/signers/node/index.js +27 -0
  35. package/dist/signers/types.cjs +18 -0
  36. package/dist/signers/types.d.cts +34 -0
  37. package/dist/signers/types.d.ts +34 -0
  38. package/dist/signers/types.js +0 -0
  39. package/dist/types.cjs +18 -0
  40. package/dist/types.d.cts +104 -0
  41. package/dist/types.d.ts +104 -0
  42. package/dist/types.js +0 -0
  43. package/package.json +53 -0
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/messages/index.ts
21
+ var messages_exports = {};
22
+ __export(messages_exports, {
23
+ buildSetSwigOperationMessage: () => buildSetSwigOperationMessage,
24
+ buildVoucherMessage: () => buildVoucherMessage,
25
+ sessionRegisterMessage: () => sessionRegisterMessage,
26
+ sessionRevokeMessage: () => sessionRevokeMessage,
27
+ voucherPayloadMessage: () => voucherPayloadMessage
28
+ });
29
+ module.exports = __toCommonJS(messages_exports);
30
+
31
+ // src/constants/index.ts
32
+ var import_web3 = require("@solana/web3.js");
33
+ var DEXTER_VAULT_PROGRAM_ID = new import_web3.PublicKey(
34
+ "Hg3wRaydFtJhYrdvYrKECacpJYDsC9Px7yKmpncj2fhc"
35
+ );
36
+ var SWIG_PROGRAM_ID = new import_web3.PublicKey(
37
+ "swigypWHEksbC64pWKwah1WTeh9JXwx8H1rJHLdbQMB"
38
+ );
39
+ var SECP256R1_PROGRAM_ID = new import_web3.PublicKey(
40
+ "Secp256r1SigVerify1111111111111111111111111"
41
+ );
42
+ var ED25519_PROGRAM_ID = new import_web3.PublicKey(
43
+ "Ed25519SigVerify111111111111111111111111111"
44
+ );
45
+ var INSTRUCTIONS_SYSVAR_ID = new import_web3.PublicKey(
46
+ "Sysvar1nstructions1111111111111111111111111"
47
+ );
48
+ var VAULT_SEED_PREFIX = Buffer.from("vault");
49
+ var DISCRIMINATORS = Object.freeze({
50
+ initialize_vault: Uint8Array.from([48, 191, 163, 44, 71, 129, 63, 164]),
51
+ set_swig: Uint8Array.from([253, 229, 89, 206, 192, 118, 137, 165]),
52
+ settle_voucher: Uint8Array.from([144, 176, 128, 220, 156, 79, 41, 54]),
53
+ request_withdrawal: Uint8Array.from([251, 85, 121, 205, 56, 201, 12, 177]),
54
+ finalize_withdrawal: Uint8Array.from([178, 87, 206, 68, 201, 186, 164, 232]),
55
+ force_release: Uint8Array.from([122, 190, 243, 252, 54, 202, 208, 234]),
56
+ rotate_passkey: Uint8Array.from([28, 134, 49, 89, 196, 34, 58, 174]),
57
+ rotate_dexter_authority: Uint8Array.from([145, 60, 4, 119, 180, 205, 236, 134]),
58
+ prove_passkey: Uint8Array.from([35, 175, 41, 143, 201, 118, 49, 184]),
59
+ settle_tab_voucher: Uint8Array.from([173, 22, 98, 31, 110, 129, 59, 161]),
60
+ register_session_key: Uint8Array.from([69, 94, 60, 44, 49, 199, 183, 233]),
61
+ revoke_session_key: Uint8Array.from([81, 192, 32, 110, 104, 116, 144, 151])
62
+ });
63
+ var OTS_SESSION_REGISTER_V1_DOMAIN = (() => {
64
+ const buf = new Uint8Array(32);
65
+ buf.set(new TextEncoder().encode("OTS_SESSION_REGISTER_V1"), 0);
66
+ return buf;
67
+ })();
68
+ var OTS_SESSION_REVOKE_V1_DOMAIN = (() => {
69
+ const buf = new Uint8Array(32);
70
+ buf.set(new TextEncoder().encode("OTS_SESSION_REVOKE_V1"), 0);
71
+ return buf;
72
+ })();
73
+
74
+ // src/messages/session.ts
75
+ function sessionRegisterMessage(args) {
76
+ if (args.sessionPubkey.length !== 32) {
77
+ throw new Error(`sessionPubkey must be 32 bytes, got ${args.sessionPubkey.length}`);
78
+ }
79
+ const buf = new Uint8Array(180);
80
+ const view = new DataView(buf.buffer);
81
+ let o = 0;
82
+ buf.set(OTS_SESSION_REGISTER_V1_DOMAIN, o);
83
+ o += 32;
84
+ buf.set(args.programId.toBytes(), o);
85
+ o += 32;
86
+ buf.set(args.vaultPda.toBytes(), o);
87
+ o += 32;
88
+ buf.set(args.sessionPubkey, o);
89
+ o += 32;
90
+ view.setBigUint64(o, args.maxAmount, true);
91
+ o += 8;
92
+ view.setBigInt64(o, args.expiresAt, true);
93
+ o += 8;
94
+ buf.set(args.allowedCounterparty.toBytes(), o);
95
+ o += 32;
96
+ view.setUint32(o, args.nonce >>> 0, true);
97
+ o += 4;
98
+ if (o !== 180) {
99
+ throw new Error(`internal: session register message wrong length ${o}, expected 180`);
100
+ }
101
+ return buf;
102
+ }
103
+ function sessionRevokeMessage(args) {
104
+ if (args.sessionPubkey.length !== 32) {
105
+ throw new Error(`sessionPubkey must be 32 bytes, got ${args.sessionPubkey.length}`);
106
+ }
107
+ const buf = new Uint8Array(128);
108
+ let o = 0;
109
+ buf.set(OTS_SESSION_REVOKE_V1_DOMAIN, o);
110
+ o += 32;
111
+ buf.set(args.programId.toBytes(), o);
112
+ o += 32;
113
+ buf.set(args.vaultPda.toBytes(), o);
114
+ o += 32;
115
+ buf.set(args.sessionPubkey, o);
116
+ o += 32;
117
+ if (o !== 128) {
118
+ throw new Error(`internal: session revoke message wrong length ${o}, expected 128`);
119
+ }
120
+ return buf;
121
+ }
122
+
123
+ // src/messages/voucher.ts
124
+ function voucherPayloadMessage(p) {
125
+ if (p.channelId.length !== 32) {
126
+ throw new Error(`channelId must be 32 bytes, got ${p.channelId.length}`);
127
+ }
128
+ const buf = new Uint8Array(44);
129
+ const view = new DataView(buf.buffer);
130
+ buf.set(p.channelId, 0);
131
+ view.setBigUint64(32, p.cumulativeAmount, true);
132
+ view.setUint32(40, p.sequenceNumber >>> 0, true);
133
+ return buf;
134
+ }
135
+ function buildVoucherMessage(channelId, cumulativeAmount, sequenceNumber) {
136
+ return voucherPayloadMessage({ channelId, cumulativeAmount, sequenceNumber });
137
+ }
138
+
139
+ // src/messages/operations.ts
140
+ var import_web32 = require("@solana/web3.js");
141
+ function buildSetSwigOperationMessage(swigStatePda) {
142
+ const prefix = Buffer.from("set_swig", "utf8");
143
+ const addressBytes = new import_web32.PublicKey(swigStatePda).toBytes();
144
+ const out = new Uint8Array(prefix.length + addressBytes.length);
145
+ out.set(prefix, 0);
146
+ out.set(addressBytes, prefix.length);
147
+ return out;
148
+ }
149
+ // Annotate the CommonJS export names for ESM import in node:
150
+ 0 && (module.exports = {
151
+ buildSetSwigOperationMessage,
152
+ buildVoucherMessage,
153
+ sessionRegisterMessage,
154
+ sessionRevokeMessage,
155
+ voucherPayloadMessage
156
+ });
@@ -0,0 +1,89 @@
1
+ import { PublicKey } from '@solana/web3.js';
2
+
3
+ /**
4
+ * Byte-deterministic session-key message builders.
5
+ *
6
+ * MUST match the on-chain Rust handlers byte-for-byte:
7
+ * - register_session_key.rs::build_registration_message → sessionRegisterMessage (180 bytes)
8
+ * - revoke_session_key.rs::build_revocation_message → sessionRevokeMessage (128 bytes)
9
+ *
10
+ * Any drift makes every signature look forged to the on-chain handler.
11
+ */
12
+
13
+ interface SessionRegisterMessageArgs {
14
+ programId: PublicKey;
15
+ vaultPda: PublicKey;
16
+ sessionPubkey: Uint8Array;
17
+ maxAmount: bigint;
18
+ expiresAt: bigint;
19
+ allowedCounterparty: PublicKey;
20
+ nonce: number;
21
+ }
22
+ /**
23
+ * 180-byte session registration message. Layout:
24
+ * 0 32 domain separator (REGISTER_DOMAIN)
25
+ * 32 32 program_id
26
+ * 64 32 vault_pda
27
+ * 96 32 session_pubkey
28
+ * 128 8 max_amount (u64 LE)
29
+ * 136 8 expires_at (i64 LE)
30
+ * 144 32 allowed_counterparty
31
+ * 176 4 nonce (u32 LE)
32
+ * ────
33
+ * 180
34
+ */
35
+ declare function sessionRegisterMessage(args: SessionRegisterMessageArgs): Uint8Array;
36
+ interface SessionRevokeMessageArgs {
37
+ programId: PublicKey;
38
+ vaultPda: PublicKey;
39
+ sessionPubkey: Uint8Array;
40
+ }
41
+ /**
42
+ * 128-byte session revocation message. Layout:
43
+ * 0 32 domain separator (REVOKE_DOMAIN)
44
+ * 32 32 program_id
45
+ * 64 32 vault_pda
46
+ * 96 32 session_pubkey
47
+ * ────
48
+ * 128
49
+ */
50
+ declare function sessionRevokeMessage(args: SessionRevokeMessageArgs): Uint8Array;
51
+
52
+ /**
53
+ * 44-byte voucher payload — the canonical bytes the session key signs per
54
+ * stream chunk.
55
+ *
56
+ * Layout:
57
+ * 0 32 channel_id
58
+ * 32 8 cumulative_amount (u64 LE)
59
+ * 40 4 sequence_number (u32 LE)
60
+ * ───
61
+ * 44
62
+ *
63
+ * NOTE: production calls this under two names — `voucherPayloadMessage`
64
+ * (x402) and `buildVoucherMessage` (dexter-api, dexter-facilitator). Both
65
+ * are exported here, pointing at the same function. Don't bikeshed.
66
+ */
67
+ interface VoucherPayloadBytes {
68
+ channelId: Uint8Array;
69
+ cumulativeAmount: bigint;
70
+ sequenceNumber: number;
71
+ }
72
+ declare function voucherPayloadMessage(p: VoucherPayloadBytes): Uint8Array;
73
+ /** Positional alias for the dexter-api/dexter-facilitator call shape. */
74
+ declare function buildVoucherMessage(channelId: Uint8Array, cumulativeAmount: bigint, sequenceNumber: number): Uint8Array;
75
+
76
+ /**
77
+ * Per-vault-operation message helpers.
78
+ *
79
+ * These are what the user's passkey signs for instructions that the
80
+ * on-chain handler verifies via the secp256r1 precompile sibling.
81
+ */
82
+ /**
83
+ * Message format for the `set_swig` instruction:
84
+ *
85
+ * bytes("set_swig") || swigStatePda (32 bytes)
86
+ */
87
+ declare function buildSetSwigOperationMessage(swigStatePda: string): Uint8Array;
88
+
89
+ export { type SessionRegisterMessageArgs, type SessionRevokeMessageArgs, type VoucherPayloadBytes, buildSetSwigOperationMessage, buildVoucherMessage, sessionRegisterMessage, sessionRevokeMessage, voucherPayloadMessage };
@@ -0,0 +1,89 @@
1
+ import { PublicKey } from '@solana/web3.js';
2
+
3
+ /**
4
+ * Byte-deterministic session-key message builders.
5
+ *
6
+ * MUST match the on-chain Rust handlers byte-for-byte:
7
+ * - register_session_key.rs::build_registration_message → sessionRegisterMessage (180 bytes)
8
+ * - revoke_session_key.rs::build_revocation_message → sessionRevokeMessage (128 bytes)
9
+ *
10
+ * Any drift makes every signature look forged to the on-chain handler.
11
+ */
12
+
13
+ interface SessionRegisterMessageArgs {
14
+ programId: PublicKey;
15
+ vaultPda: PublicKey;
16
+ sessionPubkey: Uint8Array;
17
+ maxAmount: bigint;
18
+ expiresAt: bigint;
19
+ allowedCounterparty: PublicKey;
20
+ nonce: number;
21
+ }
22
+ /**
23
+ * 180-byte session registration message. Layout:
24
+ * 0 32 domain separator (REGISTER_DOMAIN)
25
+ * 32 32 program_id
26
+ * 64 32 vault_pda
27
+ * 96 32 session_pubkey
28
+ * 128 8 max_amount (u64 LE)
29
+ * 136 8 expires_at (i64 LE)
30
+ * 144 32 allowed_counterparty
31
+ * 176 4 nonce (u32 LE)
32
+ * ────
33
+ * 180
34
+ */
35
+ declare function sessionRegisterMessage(args: SessionRegisterMessageArgs): Uint8Array;
36
+ interface SessionRevokeMessageArgs {
37
+ programId: PublicKey;
38
+ vaultPda: PublicKey;
39
+ sessionPubkey: Uint8Array;
40
+ }
41
+ /**
42
+ * 128-byte session revocation message. Layout:
43
+ * 0 32 domain separator (REVOKE_DOMAIN)
44
+ * 32 32 program_id
45
+ * 64 32 vault_pda
46
+ * 96 32 session_pubkey
47
+ * ────
48
+ * 128
49
+ */
50
+ declare function sessionRevokeMessage(args: SessionRevokeMessageArgs): Uint8Array;
51
+
52
+ /**
53
+ * 44-byte voucher payload — the canonical bytes the session key signs per
54
+ * stream chunk.
55
+ *
56
+ * Layout:
57
+ * 0 32 channel_id
58
+ * 32 8 cumulative_amount (u64 LE)
59
+ * 40 4 sequence_number (u32 LE)
60
+ * ───
61
+ * 44
62
+ *
63
+ * NOTE: production calls this under two names — `voucherPayloadMessage`
64
+ * (x402) and `buildVoucherMessage` (dexter-api, dexter-facilitator). Both
65
+ * are exported here, pointing at the same function. Don't bikeshed.
66
+ */
67
+ interface VoucherPayloadBytes {
68
+ channelId: Uint8Array;
69
+ cumulativeAmount: bigint;
70
+ sequenceNumber: number;
71
+ }
72
+ declare function voucherPayloadMessage(p: VoucherPayloadBytes): Uint8Array;
73
+ /** Positional alias for the dexter-api/dexter-facilitator call shape. */
74
+ declare function buildVoucherMessage(channelId: Uint8Array, cumulativeAmount: bigint, sequenceNumber: number): Uint8Array;
75
+
76
+ /**
77
+ * Per-vault-operation message helpers.
78
+ *
79
+ * These are what the user's passkey signs for instructions that the
80
+ * on-chain handler verifies via the secp256r1 precompile sibling.
81
+ */
82
+ /**
83
+ * Message format for the `set_swig` instruction:
84
+ *
85
+ * bytes("set_swig") || swigStatePda (32 bytes)
86
+ */
87
+ declare function buildSetSwigOperationMessage(swigStatePda: string): Uint8Array;
88
+
89
+ export { type SessionRegisterMessageArgs, type SessionRevokeMessageArgs, type VoucherPayloadBytes, buildSetSwigOperationMessage, buildVoucherMessage, sessionRegisterMessage, sessionRevokeMessage, voucherPayloadMessage };
@@ -0,0 +1,125 @@
1
+ // src/constants/index.ts
2
+ import { PublicKey } from "@solana/web3.js";
3
+ var DEXTER_VAULT_PROGRAM_ID = new PublicKey(
4
+ "Hg3wRaydFtJhYrdvYrKECacpJYDsC9Px7yKmpncj2fhc"
5
+ );
6
+ var SWIG_PROGRAM_ID = new PublicKey(
7
+ "swigypWHEksbC64pWKwah1WTeh9JXwx8H1rJHLdbQMB"
8
+ );
9
+ var SECP256R1_PROGRAM_ID = new PublicKey(
10
+ "Secp256r1SigVerify1111111111111111111111111"
11
+ );
12
+ var ED25519_PROGRAM_ID = new PublicKey(
13
+ "Ed25519SigVerify111111111111111111111111111"
14
+ );
15
+ var INSTRUCTIONS_SYSVAR_ID = new PublicKey(
16
+ "Sysvar1nstructions1111111111111111111111111"
17
+ );
18
+ var VAULT_SEED_PREFIX = Buffer.from("vault");
19
+ var DISCRIMINATORS = Object.freeze({
20
+ initialize_vault: Uint8Array.from([48, 191, 163, 44, 71, 129, 63, 164]),
21
+ set_swig: Uint8Array.from([253, 229, 89, 206, 192, 118, 137, 165]),
22
+ settle_voucher: Uint8Array.from([144, 176, 128, 220, 156, 79, 41, 54]),
23
+ request_withdrawal: Uint8Array.from([251, 85, 121, 205, 56, 201, 12, 177]),
24
+ finalize_withdrawal: Uint8Array.from([178, 87, 206, 68, 201, 186, 164, 232]),
25
+ force_release: Uint8Array.from([122, 190, 243, 252, 54, 202, 208, 234]),
26
+ rotate_passkey: Uint8Array.from([28, 134, 49, 89, 196, 34, 58, 174]),
27
+ rotate_dexter_authority: Uint8Array.from([145, 60, 4, 119, 180, 205, 236, 134]),
28
+ prove_passkey: Uint8Array.from([35, 175, 41, 143, 201, 118, 49, 184]),
29
+ settle_tab_voucher: Uint8Array.from([173, 22, 98, 31, 110, 129, 59, 161]),
30
+ register_session_key: Uint8Array.from([69, 94, 60, 44, 49, 199, 183, 233]),
31
+ revoke_session_key: Uint8Array.from([81, 192, 32, 110, 104, 116, 144, 151])
32
+ });
33
+ var OTS_SESSION_REGISTER_V1_DOMAIN = (() => {
34
+ const buf = new Uint8Array(32);
35
+ buf.set(new TextEncoder().encode("OTS_SESSION_REGISTER_V1"), 0);
36
+ return buf;
37
+ })();
38
+ var OTS_SESSION_REVOKE_V1_DOMAIN = (() => {
39
+ const buf = new Uint8Array(32);
40
+ buf.set(new TextEncoder().encode("OTS_SESSION_REVOKE_V1"), 0);
41
+ return buf;
42
+ })();
43
+
44
+ // src/messages/session.ts
45
+ function sessionRegisterMessage(args) {
46
+ if (args.sessionPubkey.length !== 32) {
47
+ throw new Error(`sessionPubkey must be 32 bytes, got ${args.sessionPubkey.length}`);
48
+ }
49
+ const buf = new Uint8Array(180);
50
+ const view = new DataView(buf.buffer);
51
+ let o = 0;
52
+ buf.set(OTS_SESSION_REGISTER_V1_DOMAIN, o);
53
+ o += 32;
54
+ buf.set(args.programId.toBytes(), o);
55
+ o += 32;
56
+ buf.set(args.vaultPda.toBytes(), o);
57
+ o += 32;
58
+ buf.set(args.sessionPubkey, o);
59
+ o += 32;
60
+ view.setBigUint64(o, args.maxAmount, true);
61
+ o += 8;
62
+ view.setBigInt64(o, args.expiresAt, true);
63
+ o += 8;
64
+ buf.set(args.allowedCounterparty.toBytes(), o);
65
+ o += 32;
66
+ view.setUint32(o, args.nonce >>> 0, true);
67
+ o += 4;
68
+ if (o !== 180) {
69
+ throw new Error(`internal: session register message wrong length ${o}, expected 180`);
70
+ }
71
+ return buf;
72
+ }
73
+ function sessionRevokeMessage(args) {
74
+ if (args.sessionPubkey.length !== 32) {
75
+ throw new Error(`sessionPubkey must be 32 bytes, got ${args.sessionPubkey.length}`);
76
+ }
77
+ const buf = new Uint8Array(128);
78
+ let o = 0;
79
+ buf.set(OTS_SESSION_REVOKE_V1_DOMAIN, o);
80
+ o += 32;
81
+ buf.set(args.programId.toBytes(), o);
82
+ o += 32;
83
+ buf.set(args.vaultPda.toBytes(), o);
84
+ o += 32;
85
+ buf.set(args.sessionPubkey, o);
86
+ o += 32;
87
+ if (o !== 128) {
88
+ throw new Error(`internal: session revoke message wrong length ${o}, expected 128`);
89
+ }
90
+ return buf;
91
+ }
92
+
93
+ // src/messages/voucher.ts
94
+ function voucherPayloadMessage(p) {
95
+ if (p.channelId.length !== 32) {
96
+ throw new Error(`channelId must be 32 bytes, got ${p.channelId.length}`);
97
+ }
98
+ const buf = new Uint8Array(44);
99
+ const view = new DataView(buf.buffer);
100
+ buf.set(p.channelId, 0);
101
+ view.setBigUint64(32, p.cumulativeAmount, true);
102
+ view.setUint32(40, p.sequenceNumber >>> 0, true);
103
+ return buf;
104
+ }
105
+ function buildVoucherMessage(channelId, cumulativeAmount, sequenceNumber) {
106
+ return voucherPayloadMessage({ channelId, cumulativeAmount, sequenceNumber });
107
+ }
108
+
109
+ // src/messages/operations.ts
110
+ import { PublicKey as PublicKey2 } from "@solana/web3.js";
111
+ function buildSetSwigOperationMessage(swigStatePda) {
112
+ const prefix = Buffer.from("set_swig", "utf8");
113
+ const addressBytes = new PublicKey2(swigStatePda).toBytes();
114
+ const out = new Uint8Array(prefix.length + addressBytes.length);
115
+ out.set(prefix, 0);
116
+ out.set(addressBytes, prefix.length);
117
+ return out;
118
+ }
119
+ export {
120
+ buildSetSwigOperationMessage,
121
+ buildVoucherMessage,
122
+ sessionRegisterMessage,
123
+ sessionRevokeMessage,
124
+ voucherPayloadMessage
125
+ };
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/precompile/index.ts
31
+ var precompile_exports = {};
32
+ __export(precompile_exports, {
33
+ COMPRESSED_PUBKEY_SERIALIZED_SIZE: () => COMPRESSED_PUBKEY_SERIALIZED_SIZE,
34
+ PRECOMPILE_DATA_START: () => PRECOMPILE_DATA_START,
35
+ SIGNATURE_OFFSETS_SERIALIZED_SIZE: () => SIGNATURE_OFFSETS_SERIALIZED_SIZE,
36
+ SIGNATURE_SERIALIZED_SIZE: () => SIGNATURE_SERIALIZED_SIZE,
37
+ buildEd25519VerifyInstruction: () => buildEd25519VerifyInstruction,
38
+ buildPrecompileMessage: () => buildPrecompileMessage,
39
+ buildSecp256r1VerifyInstruction: () => buildSecp256r1VerifyInstruction
40
+ });
41
+ module.exports = __toCommonJS(precompile_exports);
42
+
43
+ // src/precompile/secp256r1.ts
44
+ var import_web32 = require("@solana/web3.js");
45
+
46
+ // src/constants/index.ts
47
+ var import_web3 = require("@solana/web3.js");
48
+ var DEXTER_VAULT_PROGRAM_ID = new import_web3.PublicKey(
49
+ "Hg3wRaydFtJhYrdvYrKECacpJYDsC9Px7yKmpncj2fhc"
50
+ );
51
+ var SWIG_PROGRAM_ID = new import_web3.PublicKey(
52
+ "swigypWHEksbC64pWKwah1WTeh9JXwx8H1rJHLdbQMB"
53
+ );
54
+ var SECP256R1_PROGRAM_ID = new import_web3.PublicKey(
55
+ "Secp256r1SigVerify1111111111111111111111111"
56
+ );
57
+ var ED25519_PROGRAM_ID = new import_web3.PublicKey(
58
+ "Ed25519SigVerify111111111111111111111111111"
59
+ );
60
+ var INSTRUCTIONS_SYSVAR_ID = new import_web3.PublicKey(
61
+ "Sysvar1nstructions1111111111111111111111111"
62
+ );
63
+ var VAULT_SEED_PREFIX = Buffer.from("vault");
64
+ var DISCRIMINATORS = Object.freeze({
65
+ initialize_vault: Uint8Array.from([48, 191, 163, 44, 71, 129, 63, 164]),
66
+ set_swig: Uint8Array.from([253, 229, 89, 206, 192, 118, 137, 165]),
67
+ settle_voucher: Uint8Array.from([144, 176, 128, 220, 156, 79, 41, 54]),
68
+ request_withdrawal: Uint8Array.from([251, 85, 121, 205, 56, 201, 12, 177]),
69
+ finalize_withdrawal: Uint8Array.from([178, 87, 206, 68, 201, 186, 164, 232]),
70
+ force_release: Uint8Array.from([122, 190, 243, 252, 54, 202, 208, 234]),
71
+ rotate_passkey: Uint8Array.from([28, 134, 49, 89, 196, 34, 58, 174]),
72
+ rotate_dexter_authority: Uint8Array.from([145, 60, 4, 119, 180, 205, 236, 134]),
73
+ prove_passkey: Uint8Array.from([35, 175, 41, 143, 201, 118, 49, 184]),
74
+ settle_tab_voucher: Uint8Array.from([173, 22, 98, 31, 110, 129, 59, 161]),
75
+ register_session_key: Uint8Array.from([69, 94, 60, 44, 49, 199, 183, 233]),
76
+ revoke_session_key: Uint8Array.from([81, 192, 32, 110, 104, 116, 144, 151])
77
+ });
78
+ var OTS_SESSION_REGISTER_V1_DOMAIN = (() => {
79
+ const buf = new Uint8Array(32);
80
+ buf.set(new TextEncoder().encode("OTS_SESSION_REGISTER_V1"), 0);
81
+ return buf;
82
+ })();
83
+ var OTS_SESSION_REVOKE_V1_DOMAIN = (() => {
84
+ const buf = new Uint8Array(32);
85
+ buf.set(new TextEncoder().encode("OTS_SESSION_REVOKE_V1"), 0);
86
+ return buf;
87
+ })();
88
+
89
+ // src/precompile/secp256r1.ts
90
+ var SIGNATURE_OFFSETS_SERIALIZED_SIZE = 14;
91
+ var SIGNATURE_SERIALIZED_SIZE = 64;
92
+ var COMPRESSED_PUBKEY_SERIALIZED_SIZE = 33;
93
+ var PRECOMPILE_DATA_START = 2;
94
+ function buildSecp256r1VerifyInstruction(publicKey, signature, message) {
95
+ if (publicKey.length !== COMPRESSED_PUBKEY_SERIALIZED_SIZE) {
96
+ throw new Error(`expected ${COMPRESSED_PUBKEY_SERIALIZED_SIZE}-byte pubkey`);
97
+ }
98
+ if (signature.length !== SIGNATURE_SERIALIZED_SIZE) {
99
+ throw new Error(`expected ${SIGNATURE_SERIALIZED_SIZE}-byte signature`);
100
+ }
101
+ const signatureOffset = PRECOMPILE_DATA_START + SIGNATURE_OFFSETS_SERIALIZED_SIZE;
102
+ const publicKeyOffset = signatureOffset + SIGNATURE_SERIALIZED_SIZE;
103
+ const messageOffset = publicKeyOffset + COMPRESSED_PUBKEY_SERIALIZED_SIZE;
104
+ const messageSize = message.length;
105
+ const totalLen = messageOffset + messageSize;
106
+ const data = Buffer.alloc(totalLen);
107
+ data[0] = 1;
108
+ data[1] = 0;
109
+ data.writeUInt16LE(signatureOffset, PRECOMPILE_DATA_START + 0);
110
+ data.writeUInt16LE(65535, PRECOMPILE_DATA_START + 2);
111
+ data.writeUInt16LE(publicKeyOffset, PRECOMPILE_DATA_START + 4);
112
+ data.writeUInt16LE(65535, PRECOMPILE_DATA_START + 6);
113
+ data.writeUInt16LE(messageOffset, PRECOMPILE_DATA_START + 8);
114
+ data.writeUInt16LE(messageSize, PRECOMPILE_DATA_START + 10);
115
+ data.writeUInt16LE(65535, PRECOMPILE_DATA_START + 12);
116
+ Buffer.from(signature).copy(data, signatureOffset);
117
+ Buffer.from(publicKey).copy(data, publicKeyOffset);
118
+ Buffer.from(message).copy(data, messageOffset);
119
+ return new import_web32.TransactionInstruction({
120
+ keys: [],
121
+ programId: SECP256R1_PROGRAM_ID,
122
+ data
123
+ });
124
+ }
125
+ async function buildPrecompileMessage(clientDataJSON, authenticatorData) {
126
+ const subtle = globalThis.crypto?.subtle;
127
+ let clientDataHash;
128
+ if (subtle) {
129
+ const buf = await subtle.digest("SHA-256", clientDataJSON);
130
+ clientDataHash = new Uint8Array(buf);
131
+ } else {
132
+ const { createHash } = await import("crypto");
133
+ clientDataHash = createHash("sha256").update(clientDataJSON).digest();
134
+ }
135
+ const out = new Uint8Array(authenticatorData.length + 32);
136
+ out.set(authenticatorData, 0);
137
+ out.set(clientDataHash, authenticatorData.length);
138
+ return out;
139
+ }
140
+
141
+ // src/precompile/ed25519.ts
142
+ var import_web33 = require("@solana/web3.js");
143
+ function buildEd25519VerifyInstruction(pubkey, signature, message) {
144
+ if (pubkey.length !== 32) throw new Error("pubkey must be 32 bytes");
145
+ if (signature.length !== 64) throw new Error("signature must be 64 bytes");
146
+ const NUM_SIG = 1;
147
+ const PADDING = 0;
148
+ const HEADER_LEN = 2;
149
+ const OFFSETS_LEN = 14;
150
+ const DATA_START = HEADER_LEN + OFFSETS_LEN;
151
+ const data = Buffer.alloc(DATA_START + pubkey.length + signature.length + message.length);
152
+ let off = 0;
153
+ data.writeUInt8(NUM_SIG, off);
154
+ off += 1;
155
+ data.writeUInt8(PADDING, off);
156
+ off += 1;
157
+ const pubkeyOffset = DATA_START;
158
+ const signatureOffset = pubkeyOffset + pubkey.length;
159
+ const messageOffset = signatureOffset + signature.length;
160
+ data.writeUInt16LE(signatureOffset, off);
161
+ off += 2;
162
+ data.writeUInt16LE(65535, off);
163
+ off += 2;
164
+ data.writeUInt16LE(pubkeyOffset, off);
165
+ off += 2;
166
+ data.writeUInt16LE(65535, off);
167
+ off += 2;
168
+ data.writeUInt16LE(messageOffset, off);
169
+ off += 2;
170
+ data.writeUInt16LE(message.length, off);
171
+ off += 2;
172
+ data.writeUInt16LE(65535, off);
173
+ off += 2;
174
+ Buffer.from(pubkey).copy(data, pubkeyOffset);
175
+ Buffer.from(signature).copy(data, signatureOffset);
176
+ Buffer.from(message).copy(data, messageOffset);
177
+ return new import_web33.TransactionInstruction({
178
+ programId: ED25519_PROGRAM_ID,
179
+ keys: [],
180
+ data
181
+ });
182
+ }
183
+ // Annotate the CommonJS export names for ESM import in node:
184
+ 0 && (module.exports = {
185
+ COMPRESSED_PUBKEY_SERIALIZED_SIZE,
186
+ PRECOMPILE_DATA_START,
187
+ SIGNATURE_OFFSETS_SERIALIZED_SIZE,
188
+ SIGNATURE_SERIALIZED_SIZE,
189
+ buildEd25519VerifyInstruction,
190
+ buildPrecompileMessage,
191
+ buildSecp256r1VerifyInstruction
192
+ });
@@ -0,0 +1,45 @@
1
+ import { TransactionInstruction } from '@solana/web3.js';
2
+
3
+ /**
4
+ * SIMD-0075 secp256r1 precompile builder + WebAuthn precompile message
5
+ * assembler.
6
+ *
7
+ * Place a secp256r1 verify instruction IMMEDIATELY before any vault
8
+ * instruction that takes a passkey-signed op (set_swig, register_session_key,
9
+ * revoke_session_key, request_withdrawal, finalize_withdrawal, force_release,
10
+ * rotate_passkey, prove_passkey). The vault program reads
11
+ * SYSVAR_INSTRUCTIONS to introspect the sibling and rejects unless it
12
+ * verifies.
13
+ */
14
+
15
+ declare const SIGNATURE_OFFSETS_SERIALIZED_SIZE = 14;
16
+ declare const SIGNATURE_SERIALIZED_SIZE = 64;
17
+ declare const COMPRESSED_PUBKEY_SERIALIZED_SIZE = 33;
18
+ declare const PRECOMPILE_DATA_START = 2;
19
+ declare function buildSecp256r1VerifyInstruction(publicKey: Uint8Array, // 33-byte compressed P-256
20
+ signature: Uint8Array, // 64-byte (r||s)
21
+ message: Uint8Array): TransactionInstruction;
22
+ /**
23
+ * Build the bytes the precompile verifies against the WebAuthn signature:
24
+ * authenticatorData || SHA-256(clientDataJSON)
25
+ *
26
+ * Works in Node (via `node:crypto`) and the browser (via SubtleCrypto).
27
+ */
28
+ declare function buildPrecompileMessage(clientDataJSON: Uint8Array, authenticatorData: Uint8Array): Promise<Uint8Array>;
29
+
30
+ /**
31
+ * Solana Ed25519 sigverify precompile builder.
32
+ *
33
+ * Layout matches solana-sdk/sdk/src/ed25519_instruction.rs byte-for-byte:
34
+ * u8 numSigs + u8 padding + 14-byte SignatureOffsets +
35
+ * contiguous pubkey(32) || signature(64) || message
36
+ *
37
+ * Place this BEFORE vault::settle_tab_voucher (or any future ix needing
38
+ * session-key verification) in the same tx.
39
+ */
40
+
41
+ declare function buildEd25519VerifyInstruction(pubkey: Uint8Array, // 32 bytes
42
+ signature: Uint8Array, // 64 bytes
43
+ message: Uint8Array): TransactionInstruction;
44
+
45
+ export { COMPRESSED_PUBKEY_SERIALIZED_SIZE, PRECOMPILE_DATA_START, SIGNATURE_OFFSETS_SERIALIZED_SIZE, SIGNATURE_SERIALIZED_SIZE, buildEd25519VerifyInstruction, buildPrecompileMessage, buildSecp256r1VerifyInstruction };