@heyanon-arp/sdk 0.0.8 → 0.0.10

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/dist/assets.d.ts CHANGED
@@ -1,27 +1,24 @@
1
1
  /**
2
- * Well-known asset shorthand table + CAIP-19 helpers.
2
+ * Payment asset whitelist + CAIP-19 helpers.
3
3
  *
4
4
  * The protocol carries assets as `AssetIdentifier` ({ asset_id, decimals,
5
- * symbol? }) with `asset_id` always a CAIP-19 string. Operators almost
6
- * always work with two assets USDC and native SOL on either mainnet
7
- * or devnet — and typing 90-char CAIP-19 strings on every CLI call is
8
- * hostile. This module:
5
+ * symbol? }) with `asset_id` always a CAIP-19 string. Payment assets
6
+ * are a CLOSED per-cluster whitelist (mirroring the V2 contract's
7
+ * on-chain `CollateralConfig` allowlist):
9
8
  *
10
- * 1. Exports `WELL_KNOWN_ASSETS` the four mainstream entries
11
- * mapped from shorthand keys to canonical `AssetIdentifier`.
12
- * 2. Exports `resolveAsset(input)` — accepts either a shorthand key
13
- * OR a raw CAIP-19 string. Shorthand resolves from the table;
14
- * raw CAIP-19 is returned unchanged with `decimals: null`
15
- * sentinel (caller must supply via separate flag/field).
16
- * 3. Exports `CAIP19_REGEX` — the validation regex (server-side and
17
- * client-side both lean on the same source of truth).
9
+ * - solana-mainnet: SOL, USDC, USDT, ANON
10
+ * - solana-devnet: SOL only
18
11
  *
19
- * V1 launch ships only the four shorthand entriesextending the
20
- * table is a SemVer-minor patch. Adding a Solana cluster (testnet?)
21
- * is one entry. Adding a different chain (Ethereum, Polygon) is two
22
- * entries (the native + USDC equivalent on that chain).
12
+ * This module is the single source of truth the server's offer/lock
13
+ * gates and the CLI's shorthand resolution both import from here.
14
+ * Extending the list is one table entry (SemVer-minor). The server
15
+ * can additionally merge test-only entries via the
16
+ * `ARP_ASSET_WHITELIST_EXTRA` env (see server docs) — those are
17
+ * invisible to this static table by design.
23
18
  */
24
19
  import type { AssetIdentifier } from './types/body';
20
+ /** Solana clusters the protocol deploys to. */
21
+ export type SolanaCluster = 'solana-mainnet' | 'solana-devnet';
25
22
  /**
26
23
  * Solana cluster genesis-hash prefixes per CAIP-2 (`solana:<cluster_id>`).
27
24
  * The full genesis hash is 32 bytes; CAIP-2 uses the first 32 chars
@@ -44,19 +41,65 @@ export declare const SOLANA_CLUSTER_IDS: {
44
41
  */
45
42
  export declare const SLIP44_SOLANA = 501;
46
43
  /**
47
- * Canonical SPL mints for USDC across the two Solana clusters we
48
- * support at V1 launch. Source: Circle's official USDC documentation.
44
+ * Canonical mainnet SPL mints for the whitelisted tokens. Each was
45
+ * verified on-chain before listing (mint exists, decimals match,
46
+ * owner = legacy SPL Token program — Token-2022 mints are not
47
+ * supported by the escrow):
48
+ *
49
+ * - USDC: Circle's official Solana issue
50
+ * - USDT: Tether's official Solana issue
51
+ * - ANON: HeyAnon (docs.heyanon.ai → Contracts)
52
+ */
53
+ export declare const MAINNET_MINTS: {
54
+ readonly USDC: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
55
+ readonly USDT: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB";
56
+ readonly ANON: "9McvH6w97oewLmPxqQEoHUAv3u5iYMyQ9AeZZhguYf1T";
57
+ };
58
+ /**
59
+ * @deprecated Compatibility alias for the pre-whitelist public API.
60
+ * Devnet USDC is NOT a payable asset anymore (devnet pays in native
61
+ * SOL only) — this constant exists solely so existing imports keep
62
+ * compiling. Use `MAINNET_MINTS` / `ASSET_WHITELIST` instead.
49
63
  */
50
64
  export declare const USDC_MINTS: {
51
65
  readonly 'solana-mainnet': "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
52
66
  readonly 'solana-devnet': "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU";
53
67
  };
54
68
  /**
55
- * Shorthand `AssetIdentifier`. Keys follow the pattern
56
- * `<TICKER>:<CLUSTER>` so a glance tells you both the asset and the
69
+ * The payment whitelist, keyed by cluster. Closed list — an offer in
70
+ * any other asset is rejected server-side
71
+ * (`DELEGATION_ASSET_NOT_ALLOWED`). Devnet deliberately pays in
72
+ * native SOL only; SPL flows are exercised there via the server's
73
+ * `ARP_ASSET_WHITELIST_EXTRA` test hatch.
74
+ */
75
+ export declare const ASSET_WHITELIST: Readonly<Record<SolanaCluster, readonly AssetIdentifier[]>>;
76
+ /**
77
+ * Shorthand → `AssetIdentifier`, derived from the whitelist. Keys
78
+ * follow `<TICKER>:<CLUSTER>` (e.g. `USDC:solana-mainnet`,
79
+ * `SOL:solana-devnet`) so a glance tells you both the asset and the
57
80
  * cluster.
58
81
  */
59
82
  export declare const WELL_KNOWN_ASSETS: Readonly<Record<string, AssetIdentifier>>;
83
+ /**
84
+ * Lookup table keys exported for `--help` choices in the CLI.
85
+ */
86
+ export declare const WELL_KNOWN_ASSET_KEYS: readonly string[];
87
+ /** Whitelisted assets for one cluster (defensive copies). */
88
+ export declare function listWhitelistedAssets(cluster: SolanaCluster): AssetIdentifier[];
89
+ /**
90
+ * Reverse lookup: CAIP-19 `asset_id` → whitelist entry + its cluster
91
+ * and shorthand key. Returns `null` for anything not whitelisted.
92
+ */
93
+ export declare function findAssetByAssetId(assetId: string): {
94
+ asset: AssetIdentifier;
95
+ cluster: SolanaCluster;
96
+ key: string;
97
+ } | null;
98
+ /**
99
+ * Membership check. With `cluster` the asset must be listed for THAT
100
+ * cluster; without it, listed for any cluster.
101
+ */
102
+ export declare function isWhitelistedAssetId(assetId: string, cluster?: SolanaCluster): boolean;
60
103
  /**
61
104
  * CAIP-19 strict regex. Reused by:
62
105
  * - Server-side envelope validation (rejects malformed `asset_id`)
@@ -82,20 +125,14 @@ export declare function isAssetIdentifier(value: unknown): value is AssetIdentif
82
125
  * Resolve a shorthand key OR raw CAIP-19 string to an `AssetIdentifier`.
83
126
  *
84
127
  * Returns:
85
- * - shorthand match → full `AssetIdentifier` from the table
86
- * - raw CAIP-19 match`{ asset_id: input, decimals: NaN, symbol: undefined }`
128
+ * - shorthand match → full `AssetIdentifier` from the whitelist
129
+ * - raw CAIP-19 that IS whitelisted the canonical entry (decimals
130
+ * and symbol filled in)
131
+ * - raw CAIP-19 not in the whitelist → `{ asset_id: input, decimals: NaN }`
87
132
  * (caller MUST supply decimals separately — NaN is a loud signal,
88
- * not a useful default)
133
+ * not a useful default). The server will reject such assets at
134
+ * offer time unless its deploy carries matching
135
+ * `ARP_ASSET_WHITELIST_EXTRA` entries, so CLIs should warn.
89
136
  * - neither → `null`
90
- *
91
- * The NaN-on-raw-input behaviour exists because decimals can't be
92
- * inferred from CAIP-19 alone — `slip44:501` is SOL (9 decimals) but
93
- * `slip44:60` is ETH (18 decimals) and we don't ship a coin-type
94
- * registry in V1. Callers using raw CAIP-19 are expected to pass
95
- * `--rate-decimals <N>` alongside.
96
137
  */
97
138
  export declare function resolveAsset(input: string): AssetIdentifier | null;
98
- /**
99
- * Lookup table keys exported for `--help` choices in the CLI.
100
- */
101
- export declare const WELL_KNOWN_ASSET_KEYS: readonly string[];
@@ -11,9 +11,9 @@ import type { AssetIdentifier } from '../types';
11
11
  * caller pre-mapping.
12
12
  *
13
13
  * `amount` is intentionally NOT here — the concrete locked amount AND its
14
- * mint are bound at settlement via the digest (`buildReleaseDigest` binds
14
+ * mint are bound on-chain at lock time (create_lock binds
15
15
  * `amount` u64 + `mint` 32B) and on-chain in the Lock account. The
16
- * condition_hash binds the agreed TERMS (scope / pricing / currency), not
16
+ * condition_hash binds the agreed TERMS (scope / currency), not
17
17
  * the amount. (Settlement is always escrow in V1 — no `settlement_model`.
18
18
  * The per-unit rate card — `rateAmount` / `rateUnit` — is NOT bound either:
19
19
  * nothing enforces it, so it stays out of the subset.)
@@ -22,9 +22,16 @@ import type { AssetIdentifier } from '../types';
22
22
  * golden vectors in `condition-hash.test.ts` pin it.
23
23
  */
24
24
  export interface DelegationTermsSubset {
25
+ /**
26
+ * Domain/version tag baked INTO the hashed bytes. V2 dropped the
27
+ * pricing-model concept from the terms (flat is the protocol's only
28
+ * semantics, not a setting) — the tag guarantees a V2 hash can never
29
+ * collide with a V1 hash over otherwise-identical fields, and gives
30
+ * future term-set changes an explicit version knob.
31
+ */
32
+ v: 'arp-condition-v2';
25
33
  delegationId: string;
26
34
  scopeSummary: string;
27
- pricingModel: string;
28
35
  currency?: AssetIdentifier;
29
36
  }
30
37
  /**
@@ -37,7 +44,6 @@ export interface DelegationTermsSubset {
37
44
  export interface DelegationTermsInput {
38
45
  delegationId?: string;
39
46
  scopeSummary?: string;
40
- pricingModel?: string;
41
47
  currency?: AssetIdentifier;
42
48
  [other: string]: unknown;
43
49
  }
@@ -1,4 +1,6 @@
1
1
  export declare const CREATE_LOCK_DISCRIMINATOR: Uint8Array<ArrayBuffer>;
2
+ /** sha256("global:create_lock_native")[0..8] — the lamport-path variant. */
3
+ export declare const CREATE_LOCK_NATIVE_DISCRIMINATOR: Uint8Array<ArrayBuffer>;
2
4
  export interface CreateLockArgs {
3
5
  /** 32-byte lock_id (deriveLockId output). */
4
6
  lockId: Uint8Array;
@@ -6,31 +8,31 @@ export interface CreateLockArgs {
6
8
  amount: bigint;
7
9
  /** 32-byte condition_hash (deriveDelegationConditionHash output). */
8
10
  conditionHash: Uint8Array;
9
- /** u64 unix-seconds expiry. */
10
- expiry: bigint;
11
11
  }
12
12
  /**
13
- * Encode the create_lock instruction data: 8-byte disc +
14
- * Borsh-encoded `CreateLockParams { lock_id, amount, condition_hash,
15
- * expiry }`. Total 88 bytes caller wraps in a TransactionInstruction
16
- * with the matching 11-account meta list (payer, payee, config, lock,
17
- * mint, payer_token_account, escrow_account, system_program,
18
- * token_program, event_authority, program).
13
+ * Encode the create_lock / create_lock_native instruction data:
14
+ * 8-byte disc + Borsh-encoded `CreateLockParams { lock_id, amount,
15
+ * condition_hash }`. Total 80 bytes. Both variants share the SAME
16
+ * params struct only the discriminator and the account list differ
17
+ * (pass `native: true` for the lamport path).
19
18
  *
20
- * The new contract (Anchor 0.32.1 + `#[event_cpi]`) dropped:
21
- * - `is_native_sol` bool native SOL is signalled by
22
- * `mint == Pubkey::default()` (all-zero pubkey) in the mint
23
- * slot of the account list, NOT by a flag in the args.
24
- * - Caller-supplied bumps for `lock` / `vault` / `vault_authority`
25
- * — Anchor reads the bumps from `ctx.bumps` itself, and the old
26
- * `vault` + `vault_authority` PDAs are replaced by a single
27
- * `escrow_account` PDA derived from `[b"escrow", lock_id]`.
19
+ * There is NO expiry argument: `Lock.expiry` is a rolling deadline
20
+ * the chain derives from the Config windows on later transitions
21
+ * (`accept_lock` work window, `submit_work` → review window,
22
+ * `open_dispute` dispute window).
28
23
  *
29
- * SDK callers that still pass the old fields will hit a clear TS
30
- * compile error from the narrower `CreateLockArgs` shape — easier
31
- * to migrate than a silently-wrong tx.
24
+ * Account lists the caller assembles around this data:
25
+ * create_lock (SPL, 12): payer, payee, config, lock,
26
+ * collateral_config([b"collateral", mint]), mint,
27
+ * payer_token_account, escrow_account, system_program,
28
+ * token_program, event_authority, program.
29
+ * create_lock_native (9): payer, payee, config, lock,
30
+ * collateral_config([b"collateral", [0u8;32]]), escrow_account,
31
+ * system_program, event_authority, program.
32
32
  */
33
- export declare function buildCreateLockIxData(args: CreateLockArgs): Uint8Array;
33
+ export declare function buildCreateLockIxData(args: CreateLockArgs, opts?: {
34
+ native?: boolean;
35
+ }): Uint8Array;
34
36
  /**
35
37
  * Sanity check: confirm the hard-coded discriminator matches what
36
38
  * sha256("global:create_lock")[0..8] should produce. Exposed for the
@@ -1,4 +1,6 @@
1
1
  export { deriveLockId, delegationIdToBytes16, bytes16ToDelegationId } from './lock-id';
2
2
  export { deriveDelegationConditionHash, type DelegationTermsSubset, type DelegationTermsInput } from './condition-hash';
3
3
  export { parseCaip19SolanaAssetId, type ParsedSolanaAssetId } from './caip19';
4
- export { buildCreateLockIxData, computeCreateLockDiscriminator, CREATE_LOCK_DISCRIMINATOR, type CreateLockArgs, } from './create-lock';
4
+ export { buildCreateLockIxData, computeCreateLockDiscriminator, CREATE_LOCK_DISCRIMINATOR, CREATE_LOCK_NATIVE_DISCRIMINATOR, type CreateLockArgs, } from './create-lock';
5
+ export { ESCROW_PDA_SEEDS, NO_ARG_LIFECYCLE_INSTRUCTIONS, type NoArgLifecycleInstruction, instructionDiscriminator, buildLifecycleIxData, buildResolveDisputeIxData, type ResolveDisputeArgs, } from './lifecycle-instructions';
6
+ export { LOCK_ACCOUNT_SIZE, LOCK_ACCOUNT_DISCRIMINATOR, LOCK_STATE_NAMES, LOCK_TERMINAL_STATES, NATIVE_SOL_MINT_BASE58, type LockStateName, type DecodedLockAccount, decodeLockAccount, computeLockAccountDiscriminator, } from './lock-account';
@@ -0,0 +1,45 @@
1
+ /** PDA seed strings of the V2 program, verbatim from the pinned IDL. */
2
+ export declare const ESCROW_PDA_SEEDS: {
3
+ readonly LOCK: "lock";
4
+ readonly ESCROW: "escrow";
5
+ readonly CONFIG: "config";
6
+ readonly STAKE_VAULT: "stake_vault";
7
+ readonly COLLATERAL: "collateral";
8
+ readonly DISPUTE_RESOLUTION: "dispute_resolution";
9
+ readonly OPERATOR_AUTH: "operator_auth";
10
+ readonly EVENT_AUTHORITY: "__event_authority";
11
+ };
12
+ /**
13
+ * Lifecycle instructions whose data is the bare 8-byte discriminator
14
+ * (no Borsh args — the program reads the Lock account instead).
15
+ */
16
+ export declare const NO_ARG_LIFECYCLE_INSTRUCTIONS: readonly ["accept_lock", "submit_work", "claim_work_payment", "claim_work_payment_native", "cancel_lock", "cancel_lock_native", "claim_expired_work", "claim_expired_work_native", "open_dispute", "close_dispute", "close_dispute_native"];
17
+ export type NoArgLifecycleInstruction = (typeof NO_ARG_LIFECYCLE_INSTRUCTIONS)[number];
18
+ /**
19
+ * Anchor instruction discriminator: `sha256("global:<name>")[0..8]`.
20
+ * Computed (not hardcoded) so a typo'd name can never silently drift
21
+ * from the on-chain program — the IDL sha-pin on the server side
22
+ * guards the other end.
23
+ */
24
+ export declare function instructionDiscriminator(ixName: string): Uint8Array;
25
+ /**
26
+ * Instruction data for the no-arg lifecycle instructions: exactly the
27
+ * 8-byte discriminator.
28
+ */
29
+ export declare function buildLifecycleIxData(ixName: NoArgLifecycleInstruction): Uint8Array;
30
+ export interface ResolveDisputeArgs {
31
+ /** true → escrow goes to the payer; false → to the payee. */
32
+ isPayerWinner: boolean;
33
+ /** 32-byte sha256 of the operator's resolution reasoning. */
34
+ reasonHash: Uint8Array;
35
+ /** 16-byte dispute id (the `dis_<uuid>` bytes). */
36
+ disputeId: Uint8Array;
37
+ }
38
+ /**
39
+ * Instruction data for resolve_dispute / resolve_dispute_native:
40
+ * 8-byte disc + Borsh `ResolveDisputeParams { is_payer_winner: bool,
41
+ * reason_hash: [u8;32], dispute_id: [u8;16] }`. Total 57 bytes.
42
+ */
43
+ export declare function buildResolveDisputeIxData(args: ResolveDisputeArgs, opts?: {
44
+ native?: boolean;
45
+ }): Uint8Array;
@@ -0,0 +1,48 @@
1
+ export declare const LOCK_ACCOUNT_SIZE = 269;
2
+ /** sha256("account:Lock")[0..8] — pinned, verified by the test suite. */
3
+ export declare const LOCK_ACCOUNT_DISCRIMINATOR: Uint8Array<ArrayBuffer>;
4
+ /**
5
+ * On-chain `LockState` enum, discriminant order = array index.
6
+ * Mirrors the server's `EscrowLockState` strings 1:1.
7
+ */
8
+ export declare const LOCK_STATE_NAMES: readonly ["created", "canceled", "in_progress", "submitted", "paid", "revoked", "disputing", "dispute_resolved", "dispute_closed"];
9
+ export type LockStateName = (typeof LOCK_STATE_NAMES)[number];
10
+ /** Terminal lock states — no further on-chain transition exists. */
11
+ export declare const LOCK_TERMINAL_STATES: readonly LockStateName[];
12
+ /** The contract's native-SOL sentinel mint, base58 form of [0u8;32]. */
13
+ export declare const NATIVE_SOL_MINT_BASE58 = "11111111111111111111111111111111";
14
+ export interface DecodedLockAccount {
15
+ /** Bare hex64. */
16
+ lockId: string;
17
+ version: number;
18
+ /** Base58. */
19
+ payer: string;
20
+ payee: string;
21
+ /** u64 base units. */
22
+ amount: bigint;
23
+ /** Base58; `NATIVE_SOL_MINT_BASE58` for native locks. */
24
+ mint: string;
25
+ /** True when `mint` is the all-zero sentinel. */
26
+ isNative: boolean;
27
+ /** Bare hex64. */
28
+ conditionHash: string;
29
+ /** Unix seconds; 0n while `created` (rolling deadline unset). */
30
+ expiry: bigint;
31
+ state: LockStateName;
32
+ stateByte: number;
33
+ feeBpsAtLock: number;
34
+ feeRecipientAtLock: string;
35
+ workerStakeAtLock: bigint;
36
+ operatorDisputeFeeAtLock: bigint;
37
+ treasuryAtLock: string;
38
+ bump: number;
39
+ }
40
+ /**
41
+ * Decode a fetched Lock account. Throws on size/discriminator/state
42
+ * mismatches — those mean the caller fetched the wrong account or the
43
+ * deployed program drifted from the pinned layout, and a loud error
44
+ * beats silently-wrong fields.
45
+ */
46
+ export declare function decodeLockAccount(data: Uint8Array): DecodedLockAccount;
47
+ /** Test hook: the canonical discriminator computation. */
48
+ export declare function computeLockAccountDiscriminator(): Uint8Array;
package/dist/index.d.ts CHANGED
@@ -7,11 +7,10 @@
7
7
  * - keys — Ed25519 generate/sign/verify, base58btc encoding
8
8
  * - did — `did:arp:<...>` parse/format + DID document types
9
9
  * - envelope — sign / verify envelope (steps 4-6 of protocol verification)
10
- * - cosignature — receipt + dispute-response co-signatures
11
10
  * - challenge — ARP-CHALLENGE-v1 ownership proof (registration)
12
11
  * - attestation — scrypt key-link owner attestation
13
12
  * - server-chain — signed_message_hash, server_event_hash, audit walker
14
- * - settlement — ARP-SOLANA-* digest stubs (V1.5)
13
+ * - settlement — token-program detection (native + legacy SPL)
15
14
  * - purpose — domain separators (`ARP-*-v1`)
16
15
  * - utils — uuid v4, sender_nonce, RFC 3339, expires_at
17
16
  * - types — wire-level TypeScript types (Envelope, body union, identity)
@@ -24,7 +23,6 @@ export * from './canonical';
24
23
  export * from './keys';
25
24
  export * from './did';
26
25
  export * from './envelope';
27
- export * from './cosignature';
28
26
  export * from './challenge';
29
27
  export * from './attestation';
30
28
  export * from './server-chain';