@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.
- package/LICENSE +24 -0
- package/README.md +61 -0
- package/dist/constants/index.cjs +92 -0
- package/dist/constants/index.d.cts +34 -0
- package/dist/constants/index.d.ts +34 -0
- package/dist/constants/index.js +57 -0
- package/dist/counterfactual.cjs +138 -0
- package/dist/counterfactual.d.cts +17 -0
- package/dist/counterfactual.d.ts +17 -0
- package/dist/counterfactual.js +113 -0
- package/dist/index.cjs +140 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +113 -0
- package/dist/instructions/index.cjs +5016 -0
- package/dist/instructions/index.d.cts +290 -0
- package/dist/instructions/index.d.ts +290 -0
- package/dist/instructions/index.js +4989 -0
- package/dist/messages/index.cjs +156 -0
- package/dist/messages/index.d.cts +89 -0
- package/dist/messages/index.d.ts +89 -0
- package/dist/messages/index.js +125 -0
- package/dist/precompile/index.cjs +192 -0
- package/dist/precompile/index.d.cts +45 -0
- package/dist/precompile/index.d.ts +45 -0
- package/dist/precompile/index.js +149 -0
- package/dist/reader/index.cjs +121 -0
- package/dist/reader/index.d.cts +41 -0
- package/dist/reader/index.d.ts +41 -0
- package/dist/reader/index.js +93 -0
- package/dist/signers/node/index.cjs +62 -0
- package/dist/signers/node/index.d.cts +21 -0
- package/dist/signers/node/index.d.ts +21 -0
- package/dist/signers/node/index.js +27 -0
- package/dist/signers/types.cjs +18 -0
- package/dist/signers/types.d.cts +34 -0
- package/dist/signers/types.d.ts +34 -0
- package/dist/signers/types.js +0 -0
- package/dist/types.cjs +18 -0
- package/dist/types.d.cts +104 -0
- package/dist/types.d.ts +104 -0
- package/dist/types.js +0 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Dexter
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# @dexterai/vault
|
|
2
|
+
|
|
3
|
+
The canonical off-chain mirror of the dexter-vault Solana Anchor program.
|
|
4
|
+
|
|
5
|
+
This package owns every TypeScript file in the Dexter codebase that
|
|
6
|
+
produces bytes the on-chain program will verify. If you are about to
|
|
7
|
+
hand-roll an instruction builder, a precompile message, a Swig role list,
|
|
8
|
+
or a vault account decoder, stop and import from here instead.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @dexterai/vault
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Why this package exists
|
|
17
|
+
|
|
18
|
+
Three places used to hand-roll the same protocol. Drift was the default.
|
|
19
|
+
This package is the structural fix: there is exactly one TypeScript file
|
|
20
|
+
that knows how to build each instruction, encode each message, decode
|
|
21
|
+
the vault account, and provision the canonical 4-role Swig.
|
|
22
|
+
|
|
23
|
+
## Version coupling
|
|
24
|
+
|
|
25
|
+
`@dexterai/vault@0.1.x` is compatible with dexter-vault program version 2
|
|
26
|
+
(10 vault instructions plus 2 session-key instructions
|
|
27
|
+
(`register_session_key`/`revoke_session_key`) — 12 total Anchor
|
|
28
|
+
discriminators; role 3 ProgramExec for `settle_tab_voucher`). Future
|
|
29
|
+
program versions will bump the SDK major or have their delta documented
|
|
30
|
+
in CHANGELOG.
|
|
31
|
+
|
|
32
|
+
## Subpath exports
|
|
33
|
+
|
|
34
|
+
- `@dexterai/vault` — types + counterfactual derivation
|
|
35
|
+
- `@dexterai/vault/types` — `VaultState`, `ActiveSession`, `PendingWithdrawal`, `SessionKey`, `SessionScope`, `SignedVoucher`, `VoucherPayload`
|
|
36
|
+
- `@dexterai/vault/constants` — program IDs, USDC mint, all 12 discriminators
|
|
37
|
+
- `@dexterai/vault/instructions` — every builder; the canonical `buildSwigCreationBundle`
|
|
38
|
+
- `@dexterai/vault/messages` — `sessionRegisterMessage` (180 bytes), `sessionRevokeMessage` (128 bytes), `voucherPayloadMessage` / `buildVoucherMessage` (44 bytes), `buildSetSwigOperationMessage`
|
|
39
|
+
- `@dexterai/vault/reader` — `readVaultOnchain` (slim), `readVaultFull` (with active session)
|
|
40
|
+
- `@dexterai/vault/precompile` — `buildSecp256r1VerifyInstruction`, `buildPrecompileMessage`, `buildEd25519VerifyInstruction`
|
|
41
|
+
- `@dexterai/vault/signers` — `Ed25519Signer`, `PasskeySigner` interfaces
|
|
42
|
+
- `@dexterai/vault/signers/node` — `NodeEd25519Signer` (tweetnacl-backed)
|
|
43
|
+
|
|
44
|
+
## Known gaps (v0.1)
|
|
45
|
+
|
|
46
|
+
- **No `BrowserPasskeySigner`.** v0.1 ships the `PasskeySigner` interface
|
|
47
|
+
but no implementation. dexter-fe continues to hand-roll WebAuthn until
|
|
48
|
+
v0.2 (tracked as task #235). Lift target: `dexter-fe/app/lib/passkey.ts`
|
|
49
|
+
+ `dexter-fe/app/lib/passkey-anon.ts`. AAGUID/UA capture must survive
|
|
50
|
+
the lift.
|
|
51
|
+
|
|
52
|
+
## Byte-parity guarantee
|
|
53
|
+
|
|
54
|
+
`tests/byte-parity.test.ts` (added in v0.1 build, see Task 3 of the extract plan) snapshots:
|
|
55
|
+
- All 12 instruction discriminators (10 vault + 2 session-key)
|
|
56
|
+
- All 3 message layouts (180-byte registration, 128-byte revocation, 44-byte voucher)
|
|
57
|
+
- The canonical vault account decode (v2 layout)
|
|
58
|
+
- The counterfactual Swig derivation for a known seed
|
|
59
|
+
|
|
60
|
+
Any change to any of these requires an explicit snapshot update —
|
|
61
|
+
flipping a byte by accident fails CI.
|
|
@@ -0,0 +1,92 @@
|
|
|
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/constants/index.ts
|
|
21
|
+
var constants_exports = {};
|
|
22
|
+
__export(constants_exports, {
|
|
23
|
+
DEXTER_VAULT_PROGRAM_ID: () => DEXTER_VAULT_PROGRAM_ID,
|
|
24
|
+
DISCRIMINATORS: () => DISCRIMINATORS,
|
|
25
|
+
ED25519_PROGRAM_ID: () => ED25519_PROGRAM_ID,
|
|
26
|
+
INSTRUCTIONS_SYSVAR_ID: () => INSTRUCTIONS_SYSVAR_ID,
|
|
27
|
+
OTS_SESSION_REGISTER_V1_DOMAIN: () => OTS_SESSION_REGISTER_V1_DOMAIN,
|
|
28
|
+
OTS_SESSION_REVOKE_V1_DOMAIN: () => OTS_SESSION_REVOKE_V1_DOMAIN,
|
|
29
|
+
SECP256R1_PROGRAM_ID: () => SECP256R1_PROGRAM_ID,
|
|
30
|
+
SWIG_PROGRAM_ID: () => SWIG_PROGRAM_ID,
|
|
31
|
+
USDC_DEVNET: () => USDC_DEVNET,
|
|
32
|
+
USDC_MAINNET: () => USDC_MAINNET,
|
|
33
|
+
VAULT_SEED_PREFIX: () => VAULT_SEED_PREFIX
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(constants_exports);
|
|
36
|
+
var import_web3 = require("@solana/web3.js");
|
|
37
|
+
var DEXTER_VAULT_PROGRAM_ID = new import_web3.PublicKey(
|
|
38
|
+
"Hg3wRaydFtJhYrdvYrKECacpJYDsC9Px7yKmpncj2fhc"
|
|
39
|
+
);
|
|
40
|
+
var SWIG_PROGRAM_ID = new import_web3.PublicKey(
|
|
41
|
+
"swigypWHEksbC64pWKwah1WTeh9JXwx8H1rJHLdbQMB"
|
|
42
|
+
);
|
|
43
|
+
var SECP256R1_PROGRAM_ID = new import_web3.PublicKey(
|
|
44
|
+
"Secp256r1SigVerify1111111111111111111111111"
|
|
45
|
+
);
|
|
46
|
+
var ED25519_PROGRAM_ID = new import_web3.PublicKey(
|
|
47
|
+
"Ed25519SigVerify111111111111111111111111111"
|
|
48
|
+
);
|
|
49
|
+
var INSTRUCTIONS_SYSVAR_ID = new import_web3.PublicKey(
|
|
50
|
+
"Sysvar1nstructions1111111111111111111111111"
|
|
51
|
+
);
|
|
52
|
+
var USDC_MAINNET = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
53
|
+
var USDC_DEVNET = "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU";
|
|
54
|
+
var VAULT_SEED_PREFIX = Buffer.from("vault");
|
|
55
|
+
var DISCRIMINATORS = Object.freeze({
|
|
56
|
+
initialize_vault: Uint8Array.from([48, 191, 163, 44, 71, 129, 63, 164]),
|
|
57
|
+
set_swig: Uint8Array.from([253, 229, 89, 206, 192, 118, 137, 165]),
|
|
58
|
+
settle_voucher: Uint8Array.from([144, 176, 128, 220, 156, 79, 41, 54]),
|
|
59
|
+
request_withdrawal: Uint8Array.from([251, 85, 121, 205, 56, 201, 12, 177]),
|
|
60
|
+
finalize_withdrawal: Uint8Array.from([178, 87, 206, 68, 201, 186, 164, 232]),
|
|
61
|
+
force_release: Uint8Array.from([122, 190, 243, 252, 54, 202, 208, 234]),
|
|
62
|
+
rotate_passkey: Uint8Array.from([28, 134, 49, 89, 196, 34, 58, 174]),
|
|
63
|
+
rotate_dexter_authority: Uint8Array.from([145, 60, 4, 119, 180, 205, 236, 134]),
|
|
64
|
+
prove_passkey: Uint8Array.from([35, 175, 41, 143, 201, 118, 49, 184]),
|
|
65
|
+
settle_tab_voucher: Uint8Array.from([173, 22, 98, 31, 110, 129, 59, 161]),
|
|
66
|
+
register_session_key: Uint8Array.from([69, 94, 60, 44, 49, 199, 183, 233]),
|
|
67
|
+
revoke_session_key: Uint8Array.from([81, 192, 32, 110, 104, 116, 144, 151])
|
|
68
|
+
});
|
|
69
|
+
var OTS_SESSION_REGISTER_V1_DOMAIN = (() => {
|
|
70
|
+
const buf = new Uint8Array(32);
|
|
71
|
+
buf.set(new TextEncoder().encode("OTS_SESSION_REGISTER_V1"), 0);
|
|
72
|
+
return buf;
|
|
73
|
+
})();
|
|
74
|
+
var OTS_SESSION_REVOKE_V1_DOMAIN = (() => {
|
|
75
|
+
const buf = new Uint8Array(32);
|
|
76
|
+
buf.set(new TextEncoder().encode("OTS_SESSION_REVOKE_V1"), 0);
|
|
77
|
+
return buf;
|
|
78
|
+
})();
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
DEXTER_VAULT_PROGRAM_ID,
|
|
82
|
+
DISCRIMINATORS,
|
|
83
|
+
ED25519_PROGRAM_ID,
|
|
84
|
+
INSTRUCTIONS_SYSVAR_ID,
|
|
85
|
+
OTS_SESSION_REGISTER_V1_DOMAIN,
|
|
86
|
+
OTS_SESSION_REVOKE_V1_DOMAIN,
|
|
87
|
+
SECP256R1_PROGRAM_ID,
|
|
88
|
+
SWIG_PROGRAM_ID,
|
|
89
|
+
USDC_DEVNET,
|
|
90
|
+
USDC_MAINNET,
|
|
91
|
+
VAULT_SEED_PREFIX
|
|
92
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Canonical on-chain constants. Every program ID, every discriminator.
|
|
5
|
+
* If a value here changes, exactly one test snapshot in tests/byte-parity.test.ts
|
|
6
|
+
* needs to update — that's the gate.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare const DEXTER_VAULT_PROGRAM_ID: PublicKey;
|
|
10
|
+
declare const SWIG_PROGRAM_ID: PublicKey;
|
|
11
|
+
declare const SECP256R1_PROGRAM_ID: PublicKey;
|
|
12
|
+
declare const ED25519_PROGRAM_ID: PublicKey;
|
|
13
|
+
declare const INSTRUCTIONS_SYSVAR_ID: PublicKey;
|
|
14
|
+
declare const USDC_MAINNET = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
15
|
+
declare const USDC_DEVNET = "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU";
|
|
16
|
+
declare const VAULT_SEED_PREFIX: Buffer<ArrayBuffer>;
|
|
17
|
+
declare const DISCRIMINATORS: Readonly<{
|
|
18
|
+
initialize_vault: Uint8Array<ArrayBuffer>;
|
|
19
|
+
set_swig: Uint8Array<ArrayBuffer>;
|
|
20
|
+
settle_voucher: Uint8Array<ArrayBuffer>;
|
|
21
|
+
request_withdrawal: Uint8Array<ArrayBuffer>;
|
|
22
|
+
finalize_withdrawal: Uint8Array<ArrayBuffer>;
|
|
23
|
+
force_release: Uint8Array<ArrayBuffer>;
|
|
24
|
+
rotate_passkey: Uint8Array<ArrayBuffer>;
|
|
25
|
+
rotate_dexter_authority: Uint8Array<ArrayBuffer>;
|
|
26
|
+
prove_passkey: Uint8Array<ArrayBuffer>;
|
|
27
|
+
settle_tab_voucher: Uint8Array<ArrayBuffer>;
|
|
28
|
+
register_session_key: Uint8Array<ArrayBuffer>;
|
|
29
|
+
revoke_session_key: Uint8Array<ArrayBuffer>;
|
|
30
|
+
}>;
|
|
31
|
+
declare const OTS_SESSION_REGISTER_V1_DOMAIN: Uint8Array;
|
|
32
|
+
declare const OTS_SESSION_REVOKE_V1_DOMAIN: Uint8Array;
|
|
33
|
+
|
|
34
|
+
export { DEXTER_VAULT_PROGRAM_ID, DISCRIMINATORS, ED25519_PROGRAM_ID, INSTRUCTIONS_SYSVAR_ID, OTS_SESSION_REGISTER_V1_DOMAIN, OTS_SESSION_REVOKE_V1_DOMAIN, SECP256R1_PROGRAM_ID, SWIG_PROGRAM_ID, USDC_DEVNET, USDC_MAINNET, VAULT_SEED_PREFIX };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Canonical on-chain constants. Every program ID, every discriminator.
|
|
5
|
+
* If a value here changes, exactly one test snapshot in tests/byte-parity.test.ts
|
|
6
|
+
* needs to update — that's the gate.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare const DEXTER_VAULT_PROGRAM_ID: PublicKey;
|
|
10
|
+
declare const SWIG_PROGRAM_ID: PublicKey;
|
|
11
|
+
declare const SECP256R1_PROGRAM_ID: PublicKey;
|
|
12
|
+
declare const ED25519_PROGRAM_ID: PublicKey;
|
|
13
|
+
declare const INSTRUCTIONS_SYSVAR_ID: PublicKey;
|
|
14
|
+
declare const USDC_MAINNET = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
15
|
+
declare const USDC_DEVNET = "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU";
|
|
16
|
+
declare const VAULT_SEED_PREFIX: Buffer<ArrayBuffer>;
|
|
17
|
+
declare const DISCRIMINATORS: Readonly<{
|
|
18
|
+
initialize_vault: Uint8Array<ArrayBuffer>;
|
|
19
|
+
set_swig: Uint8Array<ArrayBuffer>;
|
|
20
|
+
settle_voucher: Uint8Array<ArrayBuffer>;
|
|
21
|
+
request_withdrawal: Uint8Array<ArrayBuffer>;
|
|
22
|
+
finalize_withdrawal: Uint8Array<ArrayBuffer>;
|
|
23
|
+
force_release: Uint8Array<ArrayBuffer>;
|
|
24
|
+
rotate_passkey: Uint8Array<ArrayBuffer>;
|
|
25
|
+
rotate_dexter_authority: Uint8Array<ArrayBuffer>;
|
|
26
|
+
prove_passkey: Uint8Array<ArrayBuffer>;
|
|
27
|
+
settle_tab_voucher: Uint8Array<ArrayBuffer>;
|
|
28
|
+
register_session_key: Uint8Array<ArrayBuffer>;
|
|
29
|
+
revoke_session_key: Uint8Array<ArrayBuffer>;
|
|
30
|
+
}>;
|
|
31
|
+
declare const OTS_SESSION_REGISTER_V1_DOMAIN: Uint8Array;
|
|
32
|
+
declare const OTS_SESSION_REVOKE_V1_DOMAIN: Uint8Array;
|
|
33
|
+
|
|
34
|
+
export { DEXTER_VAULT_PROGRAM_ID, DISCRIMINATORS, ED25519_PROGRAM_ID, INSTRUCTIONS_SYSVAR_ID, OTS_SESSION_REGISTER_V1_DOMAIN, OTS_SESSION_REVOKE_V1_DOMAIN, SECP256R1_PROGRAM_ID, SWIG_PROGRAM_ID, USDC_DEVNET, USDC_MAINNET, VAULT_SEED_PREFIX };
|
|
@@ -0,0 +1,57 @@
|
|
|
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 USDC_MAINNET = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
19
|
+
var USDC_DEVNET = "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU";
|
|
20
|
+
var VAULT_SEED_PREFIX = Buffer.from("vault");
|
|
21
|
+
var DISCRIMINATORS = Object.freeze({
|
|
22
|
+
initialize_vault: Uint8Array.from([48, 191, 163, 44, 71, 129, 63, 164]),
|
|
23
|
+
set_swig: Uint8Array.from([253, 229, 89, 206, 192, 118, 137, 165]),
|
|
24
|
+
settle_voucher: Uint8Array.from([144, 176, 128, 220, 156, 79, 41, 54]),
|
|
25
|
+
request_withdrawal: Uint8Array.from([251, 85, 121, 205, 56, 201, 12, 177]),
|
|
26
|
+
finalize_withdrawal: Uint8Array.from([178, 87, 206, 68, 201, 186, 164, 232]),
|
|
27
|
+
force_release: Uint8Array.from([122, 190, 243, 252, 54, 202, 208, 234]),
|
|
28
|
+
rotate_passkey: Uint8Array.from([28, 134, 49, 89, 196, 34, 58, 174]),
|
|
29
|
+
rotate_dexter_authority: Uint8Array.from([145, 60, 4, 119, 180, 205, 236, 134]),
|
|
30
|
+
prove_passkey: Uint8Array.from([35, 175, 41, 143, 201, 118, 49, 184]),
|
|
31
|
+
settle_tab_voucher: Uint8Array.from([173, 22, 98, 31, 110, 129, 59, 161]),
|
|
32
|
+
register_session_key: Uint8Array.from([69, 94, 60, 44, 49, 199, 183, 233]),
|
|
33
|
+
revoke_session_key: Uint8Array.from([81, 192, 32, 110, 104, 116, 144, 151])
|
|
34
|
+
});
|
|
35
|
+
var OTS_SESSION_REGISTER_V1_DOMAIN = (() => {
|
|
36
|
+
const buf = new Uint8Array(32);
|
|
37
|
+
buf.set(new TextEncoder().encode("OTS_SESSION_REGISTER_V1"), 0);
|
|
38
|
+
return buf;
|
|
39
|
+
})();
|
|
40
|
+
var OTS_SESSION_REVOKE_V1_DOMAIN = (() => {
|
|
41
|
+
const buf = new Uint8Array(32);
|
|
42
|
+
buf.set(new TextEncoder().encode("OTS_SESSION_REVOKE_V1"), 0);
|
|
43
|
+
return buf;
|
|
44
|
+
})();
|
|
45
|
+
export {
|
|
46
|
+
DEXTER_VAULT_PROGRAM_ID,
|
|
47
|
+
DISCRIMINATORS,
|
|
48
|
+
ED25519_PROGRAM_ID,
|
|
49
|
+
INSTRUCTIONS_SYSVAR_ID,
|
|
50
|
+
OTS_SESSION_REGISTER_V1_DOMAIN,
|
|
51
|
+
OTS_SESSION_REVOKE_V1_DOMAIN,
|
|
52
|
+
SECP256R1_PROGRAM_ID,
|
|
53
|
+
SWIG_PROGRAM_ID,
|
|
54
|
+
USDC_DEVNET,
|
|
55
|
+
USDC_MAINNET,
|
|
56
|
+
VAULT_SEED_PREFIX
|
|
57
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
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/counterfactual.ts
|
|
31
|
+
var counterfactual_exports = {};
|
|
32
|
+
__export(counterfactual_exports, {
|
|
33
|
+
deriveCounterfactualAddresses: () => deriveCounterfactualAddresses
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(counterfactual_exports);
|
|
36
|
+
var import_lib2 = require("@swig-wallet/lib");
|
|
37
|
+
|
|
38
|
+
// src/instructions/swigBundle.ts
|
|
39
|
+
var import_node_crypto = require("crypto");
|
|
40
|
+
var import_kit = require("@swig-wallet/kit");
|
|
41
|
+
var import_lib = require("@swig-wallet/lib");
|
|
42
|
+
var import_bs58 = __toESM(require("bs58"), 1);
|
|
43
|
+
var import_web32 = require("@solana/web3.js");
|
|
44
|
+
|
|
45
|
+
// src/constants/index.ts
|
|
46
|
+
var import_web3 = require("@solana/web3.js");
|
|
47
|
+
var DEXTER_VAULT_PROGRAM_ID = new import_web3.PublicKey(
|
|
48
|
+
"Hg3wRaydFtJhYrdvYrKECacpJYDsC9Px7yKmpncj2fhc"
|
|
49
|
+
);
|
|
50
|
+
var SWIG_PROGRAM_ID = new import_web3.PublicKey(
|
|
51
|
+
"swigypWHEksbC64pWKwah1WTeh9JXwx8H1rJHLdbQMB"
|
|
52
|
+
);
|
|
53
|
+
var SECP256R1_PROGRAM_ID = new import_web3.PublicKey(
|
|
54
|
+
"Secp256r1SigVerify1111111111111111111111111"
|
|
55
|
+
);
|
|
56
|
+
var ED25519_PROGRAM_ID = new import_web3.PublicKey(
|
|
57
|
+
"Ed25519SigVerify111111111111111111111111111"
|
|
58
|
+
);
|
|
59
|
+
var INSTRUCTIONS_SYSVAR_ID = new import_web3.PublicKey(
|
|
60
|
+
"Sysvar1nstructions1111111111111111111111111"
|
|
61
|
+
);
|
|
62
|
+
var VAULT_SEED_PREFIX = Buffer.from("vault");
|
|
63
|
+
var DISCRIMINATORS = Object.freeze({
|
|
64
|
+
initialize_vault: Uint8Array.from([48, 191, 163, 44, 71, 129, 63, 164]),
|
|
65
|
+
set_swig: Uint8Array.from([253, 229, 89, 206, 192, 118, 137, 165]),
|
|
66
|
+
settle_voucher: Uint8Array.from([144, 176, 128, 220, 156, 79, 41, 54]),
|
|
67
|
+
request_withdrawal: Uint8Array.from([251, 85, 121, 205, 56, 201, 12, 177]),
|
|
68
|
+
finalize_withdrawal: Uint8Array.from([178, 87, 206, 68, 201, 186, 164, 232]),
|
|
69
|
+
force_release: Uint8Array.from([122, 190, 243, 252, 54, 202, 208, 234]),
|
|
70
|
+
rotate_passkey: Uint8Array.from([28, 134, 49, 89, 196, 34, 58, 174]),
|
|
71
|
+
rotate_dexter_authority: Uint8Array.from([145, 60, 4, 119, 180, 205, 236, 134]),
|
|
72
|
+
prove_passkey: Uint8Array.from([35, 175, 41, 143, 201, 118, 49, 184]),
|
|
73
|
+
settle_tab_voucher: Uint8Array.from([173, 22, 98, 31, 110, 129, 59, 161]),
|
|
74
|
+
register_session_key: Uint8Array.from([69, 94, 60, 44, 49, 199, 183, 233]),
|
|
75
|
+
revoke_session_key: Uint8Array.from([81, 192, 32, 110, 104, 116, 144, 151])
|
|
76
|
+
});
|
|
77
|
+
var OTS_SESSION_REGISTER_V1_DOMAIN = (() => {
|
|
78
|
+
const buf = new Uint8Array(32);
|
|
79
|
+
buf.set(new TextEncoder().encode("OTS_SESSION_REGISTER_V1"), 0);
|
|
80
|
+
return buf;
|
|
81
|
+
})();
|
|
82
|
+
var OTS_SESSION_REVOKE_V1_DOMAIN = (() => {
|
|
83
|
+
const buf = new Uint8Array(32);
|
|
84
|
+
buf.set(new TextEncoder().encode("OTS_SESSION_REVOKE_V1"), 0);
|
|
85
|
+
return buf;
|
|
86
|
+
})();
|
|
87
|
+
|
|
88
|
+
// src/instructions/swigBundle.ts
|
|
89
|
+
var SWIG_ID_DOMAIN = "dexter-swig-id:v1:";
|
|
90
|
+
var DEFAULT_SESSION_TTL_SECONDS = BigInt(30 * 24 * 60 * 60);
|
|
91
|
+
var DEFAULT_SPEND_LIMIT_ATOMIC = BigInt(1e9);
|
|
92
|
+
var SWIG_PROGRAM_EXEC_PREFIX = new Uint8Array([
|
|
93
|
+
178,
|
|
94
|
+
87,
|
|
95
|
+
206,
|
|
96
|
+
68,
|
|
97
|
+
201,
|
|
98
|
+
186,
|
|
99
|
+
164,
|
|
100
|
+
232
|
|
101
|
+
]);
|
|
102
|
+
var SWIG_PROGRAM_EXEC_PREFIX_SETTLE_TAB = new Uint8Array([
|
|
103
|
+
173,
|
|
104
|
+
22,
|
|
105
|
+
98,
|
|
106
|
+
31,
|
|
107
|
+
110,
|
|
108
|
+
129,
|
|
109
|
+
59,
|
|
110
|
+
161
|
|
111
|
+
]);
|
|
112
|
+
function deriveSwigId(identitySeed, hmacKey) {
|
|
113
|
+
if (hmacKey.length !== 32) {
|
|
114
|
+
throw new Error(`hmacKey must be 32 bytes, got ${hmacKey.length}`);
|
|
115
|
+
}
|
|
116
|
+
return (0, import_node_crypto.createHmac)("sha256", Buffer.from(hmacKey)).update(SWIG_ID_DOMAIN).update(Buffer.from(identitySeed)).digest();
|
|
117
|
+
}
|
|
118
|
+
async function expectedSwigAddressFor(identitySeed, hmacKey) {
|
|
119
|
+
const swigId = deriveSwigId(identitySeed, hmacKey);
|
|
120
|
+
return String(await (0, import_kit.findSwigPda)(swigId));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// src/counterfactual.ts
|
|
124
|
+
async function deriveCounterfactualAddresses(args) {
|
|
125
|
+
if (args.identitySeed.length === 0) {
|
|
126
|
+
throw new Error("identitySeed must be non-empty");
|
|
127
|
+
}
|
|
128
|
+
const swigStateAddress = await expectedSwigAddressFor(args.identitySeed, args.hmacKey);
|
|
129
|
+
const [walletPda] = await (0, import_lib2.findSwigSystemAddressPdaRaw)(swigStateAddress);
|
|
130
|
+
return {
|
|
131
|
+
swigStateAddress,
|
|
132
|
+
swigWalletAddress: walletPda.toBase58()
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
136
|
+
0 && (module.exports = {
|
|
137
|
+
deriveCounterfactualAddresses
|
|
138
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Counterfactual Swig address derivation — derive both Swig PDAs
|
|
3
|
+
* (state + wallet-address) without an RPC call and without deploying.
|
|
4
|
+
*
|
|
5
|
+
* Used by enrollment flows that show a user a deposit address before the
|
|
6
|
+
* Swig is on chain.
|
|
7
|
+
*/
|
|
8
|
+
interface CounterfactualAddresses {
|
|
9
|
+
swigStateAddress: string;
|
|
10
|
+
swigWalletAddress: string;
|
|
11
|
+
}
|
|
12
|
+
declare function deriveCounterfactualAddresses(args: {
|
|
13
|
+
identitySeed: Uint8Array;
|
|
14
|
+
hmacKey: Uint8Array;
|
|
15
|
+
}): Promise<CounterfactualAddresses>;
|
|
16
|
+
|
|
17
|
+
export { type CounterfactualAddresses, deriveCounterfactualAddresses };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Counterfactual Swig address derivation — derive both Swig PDAs
|
|
3
|
+
* (state + wallet-address) without an RPC call and without deploying.
|
|
4
|
+
*
|
|
5
|
+
* Used by enrollment flows that show a user a deposit address before the
|
|
6
|
+
* Swig is on chain.
|
|
7
|
+
*/
|
|
8
|
+
interface CounterfactualAddresses {
|
|
9
|
+
swigStateAddress: string;
|
|
10
|
+
swigWalletAddress: string;
|
|
11
|
+
}
|
|
12
|
+
declare function deriveCounterfactualAddresses(args: {
|
|
13
|
+
identitySeed: Uint8Array;
|
|
14
|
+
hmacKey: Uint8Array;
|
|
15
|
+
}): Promise<CounterfactualAddresses>;
|
|
16
|
+
|
|
17
|
+
export { type CounterfactualAddresses, deriveCounterfactualAddresses };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// src/counterfactual.ts
|
|
2
|
+
import { findSwigSystemAddressPdaRaw } from "@swig-wallet/lib";
|
|
3
|
+
|
|
4
|
+
// src/instructions/swigBundle.ts
|
|
5
|
+
import { createHmac } from "crypto";
|
|
6
|
+
import {
|
|
7
|
+
getInstructionsFromContext,
|
|
8
|
+
findSwigPda,
|
|
9
|
+
fetchNullableSwig
|
|
10
|
+
} from "@swig-wallet/kit";
|
|
11
|
+
import {
|
|
12
|
+
Actions,
|
|
13
|
+
createProgramExecAuthorityInfo,
|
|
14
|
+
createEd25519AuthorityInfo,
|
|
15
|
+
createEd25519SessionAuthorityInfo,
|
|
16
|
+
getCreateSwigWithMultipleAuthoritiesInstructionContextBuilder
|
|
17
|
+
} from "@swig-wallet/lib";
|
|
18
|
+
import bs58 from "bs58";
|
|
19
|
+
import { PublicKey as PublicKey2 } from "@solana/web3.js";
|
|
20
|
+
|
|
21
|
+
// src/constants/index.ts
|
|
22
|
+
import { PublicKey } from "@solana/web3.js";
|
|
23
|
+
var DEXTER_VAULT_PROGRAM_ID = new PublicKey(
|
|
24
|
+
"Hg3wRaydFtJhYrdvYrKECacpJYDsC9Px7yKmpncj2fhc"
|
|
25
|
+
);
|
|
26
|
+
var SWIG_PROGRAM_ID = new PublicKey(
|
|
27
|
+
"swigypWHEksbC64pWKwah1WTeh9JXwx8H1rJHLdbQMB"
|
|
28
|
+
);
|
|
29
|
+
var SECP256R1_PROGRAM_ID = new PublicKey(
|
|
30
|
+
"Secp256r1SigVerify1111111111111111111111111"
|
|
31
|
+
);
|
|
32
|
+
var ED25519_PROGRAM_ID = new PublicKey(
|
|
33
|
+
"Ed25519SigVerify111111111111111111111111111"
|
|
34
|
+
);
|
|
35
|
+
var INSTRUCTIONS_SYSVAR_ID = new PublicKey(
|
|
36
|
+
"Sysvar1nstructions1111111111111111111111111"
|
|
37
|
+
);
|
|
38
|
+
var VAULT_SEED_PREFIX = Buffer.from("vault");
|
|
39
|
+
var DISCRIMINATORS = Object.freeze({
|
|
40
|
+
initialize_vault: Uint8Array.from([48, 191, 163, 44, 71, 129, 63, 164]),
|
|
41
|
+
set_swig: Uint8Array.from([253, 229, 89, 206, 192, 118, 137, 165]),
|
|
42
|
+
settle_voucher: Uint8Array.from([144, 176, 128, 220, 156, 79, 41, 54]),
|
|
43
|
+
request_withdrawal: Uint8Array.from([251, 85, 121, 205, 56, 201, 12, 177]),
|
|
44
|
+
finalize_withdrawal: Uint8Array.from([178, 87, 206, 68, 201, 186, 164, 232]),
|
|
45
|
+
force_release: Uint8Array.from([122, 190, 243, 252, 54, 202, 208, 234]),
|
|
46
|
+
rotate_passkey: Uint8Array.from([28, 134, 49, 89, 196, 34, 58, 174]),
|
|
47
|
+
rotate_dexter_authority: Uint8Array.from([145, 60, 4, 119, 180, 205, 236, 134]),
|
|
48
|
+
prove_passkey: Uint8Array.from([35, 175, 41, 143, 201, 118, 49, 184]),
|
|
49
|
+
settle_tab_voucher: Uint8Array.from([173, 22, 98, 31, 110, 129, 59, 161]),
|
|
50
|
+
register_session_key: Uint8Array.from([69, 94, 60, 44, 49, 199, 183, 233]),
|
|
51
|
+
revoke_session_key: Uint8Array.from([81, 192, 32, 110, 104, 116, 144, 151])
|
|
52
|
+
});
|
|
53
|
+
var OTS_SESSION_REGISTER_V1_DOMAIN = (() => {
|
|
54
|
+
const buf = new Uint8Array(32);
|
|
55
|
+
buf.set(new TextEncoder().encode("OTS_SESSION_REGISTER_V1"), 0);
|
|
56
|
+
return buf;
|
|
57
|
+
})();
|
|
58
|
+
var OTS_SESSION_REVOKE_V1_DOMAIN = (() => {
|
|
59
|
+
const buf = new Uint8Array(32);
|
|
60
|
+
buf.set(new TextEncoder().encode("OTS_SESSION_REVOKE_V1"), 0);
|
|
61
|
+
return buf;
|
|
62
|
+
})();
|
|
63
|
+
|
|
64
|
+
// src/instructions/swigBundle.ts
|
|
65
|
+
var SWIG_ID_DOMAIN = "dexter-swig-id:v1:";
|
|
66
|
+
var DEFAULT_SESSION_TTL_SECONDS = BigInt(30 * 24 * 60 * 60);
|
|
67
|
+
var DEFAULT_SPEND_LIMIT_ATOMIC = BigInt(1e9);
|
|
68
|
+
var SWIG_PROGRAM_EXEC_PREFIX = new Uint8Array([
|
|
69
|
+
178,
|
|
70
|
+
87,
|
|
71
|
+
206,
|
|
72
|
+
68,
|
|
73
|
+
201,
|
|
74
|
+
186,
|
|
75
|
+
164,
|
|
76
|
+
232
|
|
77
|
+
]);
|
|
78
|
+
var SWIG_PROGRAM_EXEC_PREFIX_SETTLE_TAB = new Uint8Array([
|
|
79
|
+
173,
|
|
80
|
+
22,
|
|
81
|
+
98,
|
|
82
|
+
31,
|
|
83
|
+
110,
|
|
84
|
+
129,
|
|
85
|
+
59,
|
|
86
|
+
161
|
|
87
|
+
]);
|
|
88
|
+
function deriveSwigId(identitySeed, hmacKey) {
|
|
89
|
+
if (hmacKey.length !== 32) {
|
|
90
|
+
throw new Error(`hmacKey must be 32 bytes, got ${hmacKey.length}`);
|
|
91
|
+
}
|
|
92
|
+
return createHmac("sha256", Buffer.from(hmacKey)).update(SWIG_ID_DOMAIN).update(Buffer.from(identitySeed)).digest();
|
|
93
|
+
}
|
|
94
|
+
async function expectedSwigAddressFor(identitySeed, hmacKey) {
|
|
95
|
+
const swigId = deriveSwigId(identitySeed, hmacKey);
|
|
96
|
+
return String(await findSwigPda(swigId));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// src/counterfactual.ts
|
|
100
|
+
async function deriveCounterfactualAddresses(args) {
|
|
101
|
+
if (args.identitySeed.length === 0) {
|
|
102
|
+
throw new Error("identitySeed must be non-empty");
|
|
103
|
+
}
|
|
104
|
+
const swigStateAddress = await expectedSwigAddressFor(args.identitySeed, args.hmacKey);
|
|
105
|
+
const [walletPda] = await findSwigSystemAddressPdaRaw(swigStateAddress);
|
|
106
|
+
return {
|
|
107
|
+
swigStateAddress,
|
|
108
|
+
swigWalletAddress: walletPda.toBase58()
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export {
|
|
112
|
+
deriveCounterfactualAddresses
|
|
113
|
+
};
|