@meddleware/nft-gate-client 0.0.4 → 0.0.5

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,11 @@
1
+ import type { Challenge } from './types.js';
2
+ /**
3
+ * Fetch a fresh challenge from a gateway's `GET /v1/challenge` endpoint. Tolerates both
4
+ * `expiresAt` (camelCase) and `expires_at` (snake_case) response shapes.
5
+ *
6
+ * @throws {Error} if the network request fails or the gateway returns a non-2xx status.
7
+ * @throws {Error} if the response body is missing the required `nonce` field.
8
+ */
9
+ export declare function fetchChallenge(gatewayHost: string, opts?: {
10
+ signal?: AbortSignal;
11
+ }): Promise<Challenge>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * `@meddleware/nft-gate-client` — client-side helpers for the `access_gate` primitive.
3
+ *
4
+ * Client-side only: ownership queries, purchase/consume PTB builders, challenge signing,
5
+ * and access-proof assembly. Server-side verification lives in the Rust gateway.
6
+ */
7
+ export type { AccessGateConfig, GateAdminContext, OwnedGate, Challenge, AccessProof, OwnedAccessNft, OwnedObjectsClient, SuiObjectClient, } from './types.js';
8
+ export { fetchAccessNfts, ownsAccessNft, parseOwnedAccessNft, fetchAccessNftById, parseAdminCap, parseGate, fetchAdminCaps, fetchGate, fetchOwnedGates, } from './ownership.js';
9
+ export { buildPurchaseTx, buildConsumeTx, buildCreateGateTx, buildSetPriceTx, buildSetPaymentRecipientTx, buildSetPausedTx, buildSetDefaultUsesTx, buildSetSoulboundTx, buildSetAutoBurnAtZeroTx, buildSetNftNameTx, buildSetNftImageUrlTx, buildSetNftDescriptionTx, buildAirdropTx, buildMakeGateImmutableTx, } from './ptb.js';
10
+ export { fetchChallenge } from './challenge.js';
11
+ export { personalMessageForNonce, encodeAccessProof, decodeAccessProof, buildAccessProof, } from './proof.js';
12
+ export type { PersonalMessageSigner } from './proof.js';
@@ -0,0 +1,69 @@
1
+ import type { OwnedAccessNft, OwnedGate, OwnedObjectsClient, SuiObjectClient } from './types.js';
2
+ /**
3
+ * Parse a single `getOwnedObjects`/`getObject` entry into an {@link OwnedAccessNft}, or `null`
4
+ * if it is not an access NFT. Validates the object **type** when present (typed), and reads the
5
+ * nested `data.fields` deterministically.
6
+ */
7
+ export declare function parseOwnedAccessNft(entry: any): OwnedAccessNft | null;
8
+ /**
9
+ * Typed single-object read of one access NFT by id (`getObject` with `showType`+`showContent`),
10
+ * used when a UI needs the **exact** `usesRemaining` reliably rather than the best-effort parse
11
+ * of an owned-objects page. Returns `null` if the object is missing or not an access NFT.
12
+ *
13
+ * @throws {Error} if the RPC call fails at the network or transport layer.
14
+ */
15
+ export declare function fetchAccessNftById(client: SuiObjectClient, objectId: string): Promise<OwnedAccessNft | null>;
16
+ /**
17
+ * Fetch all access NFTs of `nftType` owned by `owner`, optionally restricted to a specific
18
+ * `gateId`. Uses `getOwnedObjects` filtered by `StructType` (the standard owned-objects query).
19
+ *
20
+ * @throws {Error} if the RPC call fails at the network or transport layer.
21
+ */
22
+ export declare function fetchAccessNfts(client: OwnedObjectsClient, owner: string, nftType: string, gateId?: string): Promise<OwnedAccessNft[]>;
23
+ /**
24
+ * True if `owner` holds at least one access NFT of `nftType` (optionally for `gateId`).
25
+ * This is the cheap check a frontend runs to decide whether to show a gated option, and a
26
+ * gateway runs (server-side) as part of access verification.
27
+ *
28
+ * @throws {Error} if the underlying RPC call fails.
29
+ */
30
+ export declare function ownsAccessNft(client: OwnedObjectsClient, owner: string, nftType: string, gateId?: string): Promise<boolean>;
31
+ /**
32
+ * Parse a single `getOwnedObjects`/`getObject` entry into `{ adminCapId, gateId }`, or `null` if
33
+ * it is not an `AdminCap`. Validates the object **type** when present and reads `fields.gate_id`.
34
+ */
35
+ export declare function parseAdminCap(entry: any): {
36
+ adminCapId: string;
37
+ gateId: string;
38
+ } | null;
39
+ /**
40
+ * Parse a `getObject` entry for a `Gate` shared object into an {@link OwnedGate} (minus
41
+ * `adminCapId`, which comes from the owning cap). Returns `null` if the object is missing its
42
+ * expected `Gate` fields.
43
+ */
44
+ export declare function parseGate(entry: any): Omit<OwnedGate, 'adminCapId'> | null;
45
+ /**
46
+ * List the `{ adminCapId, gateId }` pairs for every `access_gate::AdminCap` owned by `owner`
47
+ * under `packageId`. Uses `getOwnedObjects` filtered by `StructType` (the standard query).
48
+ *
49
+ * @throws {Error} if the underlying RPC call fails.
50
+ */
51
+ export declare function fetchAdminCaps(client: OwnedObjectsClient, owner: string, packageId: string): Promise<{
52
+ adminCapId: string;
53
+ gateId: string;
54
+ }[]>;
55
+ /**
56
+ * Typed single-object read of one `Gate` by id, returning its parsed state (without `adminCapId`).
57
+ * Returns `null` if the object is missing or not a `Gate`.
58
+ *
59
+ * @throws {Error} if the RPC call fails at the network or transport layer.
60
+ */
61
+ export declare function fetchGate(client: SuiObjectClient, gateId: string): Promise<Omit<OwnedGate, 'adminCapId'> | null>;
62
+ /**
63
+ * Fetch every gate `owner` administers: list their owned `AdminCap`s, then fetch each referenced
64
+ * `Gate` shared object and merge in the owning `adminCapId`. Gates whose object can no longer be
65
+ * read (e.g. deleted) are skipped.
66
+ *
67
+ * @throws {Error} if an underlying RPC call fails at the network or transport layer.
68
+ */
69
+ export declare function fetchOwnedGates(client: OwnedObjectsClient & SuiObjectClient, owner: string, packageId: string): Promise<OwnedGate[]>;
@@ -0,0 +1,27 @@
1
+ import type { AccessProof, Challenge } from './types.js';
2
+ /**
3
+ * The exact bytes a wallet signs (as a personal message) to answer a challenge. Both the
4
+ * client (signing) and the gateway (verifying) MUST derive the message identically.
5
+ */
6
+ export declare function personalMessageForNonce(nonce: string): Uint8Array;
7
+ /** Encode a proof as the compact Bearer token carried in the relay auth header. */
8
+ export declare function encodeAccessProof(proof: AccessProof): string;
9
+ /** Decode a proof token produced by {@link encodeAccessProof}. Throws on malformed input. */
10
+ export declare function decodeAccessProof(token: string): AccessProof;
11
+ /** A wallet-provided personal-message signer (e.g. wallet-standard `sui:signPersonalMessage`). */
12
+ export type PersonalMessageSigner = (message: Uint8Array) => Promise<{
13
+ signature: string;
14
+ }>;
15
+ /**
16
+ * Sign a challenge and assemble the encoded access-proof token to hand to any gateway as its
17
+ * auth bearer (e.g. an upload-relay client's auth-token option, an `Authorization` header).
18
+ *
19
+ * @throws {Error} if the wallet signer rejects or fails to sign the message.
20
+ */
21
+ export declare function buildAccessProof(opts: {
22
+ address: string;
23
+ challenge: Challenge;
24
+ sign: PersonalMessageSigner;
25
+ /** Present for single-use gates: the `consume` tx digest. */
26
+ consumeDigest?: string;
27
+ }): Promise<string>;
package/dist/ptb.d.ts ADDED
@@ -0,0 +1,54 @@
1
+ import { Transaction } from '@mysten/sui/transactions';
2
+ import type { AccessGateConfig, GateAdminContext } from './types.js';
3
+ /**
4
+ * Build a PTB that purchases access: split `priceMist` from the gas coin and call
5
+ * `access_gate::purchase(gate, payment)`. Overpayment is refunded on-chain, so the split
6
+ * must be exactly the price. The caller signs + executes with their wallet.
7
+ */
8
+ export declare function buildPurchaseTx(cfg: AccessGateConfig, priceMist: bigint | number): Transaction;
9
+ /**
10
+ * Build a PTB that consumes one use of a single-use NFT, binding it to `nonce`. Selects
11
+ * `consume` or `consume_soulbound` from `cfg.soulbound`. For unlimited passes there is
12
+ * nothing to consume — do not call this.
13
+ */
14
+ export declare function buildConsumeTx(cfg: AccessGateConfig, nftId: string, nonce: string): Transaction;
15
+ /**
16
+ * Build a PTB that creates a new gate. Mostly for tooling/operators; the frontend usually
17
+ * only purchases/consumes an existing gate.
18
+ */
19
+ export declare function buildCreateGateTx(packageId: string, opts: {
20
+ priceMist: bigint | number;
21
+ paymentRecipient: string;
22
+ defaultUses: bigint | number;
23
+ soulbound: boolean;
24
+ autoBurnAtZero: boolean;
25
+ nftName: string;
26
+ nftImageUrl: string;
27
+ nftDescription: string;
28
+ }): Transaction;
29
+ /** Set the gate price (in MIST) charged by future `purchase` calls (0 = free). */
30
+ export declare function buildSetPriceTx(ctx: GateAdminContext, priceMist: bigint | number): Transaction;
31
+ /** Redirect future purchase payments to a new recipient address. */
32
+ export declare function buildSetPaymentRecipientTx(ctx: GateAdminContext, recipient: string): Transaction;
33
+ /** Pause or unpause `purchase` (paused ⇒ `purchase` aborts with `E_PAUSED`). */
34
+ export declare function buildSetPausedTx(ctx: GateAdminContext, paused: boolean): Transaction;
35
+ /** Change the default uses for future mints (0 ⇒ unlimited pass; N ⇒ single-use with N). */
36
+ export declare function buildSetDefaultUsesTx(ctx: GateAdminContext, defaultUses: bigint | number): Transaction;
37
+ /** Switch the soulbound flag for future mints (does not affect already-minted NFTs). */
38
+ export declare function buildSetSoulboundTx(ctx: GateAdminContext, soulbound: boolean): Transaction;
39
+ /** Toggle the auto-burn-at-zero policy for future mints. */
40
+ export declare function buildSetAutoBurnAtZeroTx(ctx: GateAdminContext, autoBurn: boolean): Transaction;
41
+ /** Update the default NFT display name for future mints. */
42
+ export declare function buildSetNftNameTx(ctx: GateAdminContext, name: string): Transaction;
43
+ /** Update the default NFT image URL for future mints. */
44
+ export declare function buildSetNftImageUrlTx(ctx: GateAdminContext, url: string): Transaction;
45
+ /** Update the default NFT description for future mints. */
46
+ export declare function buildSetNftDescriptionTx(ctx: GateAdminContext, description: string): Transaction;
47
+ /** AdminCap-gated free grant (airdrop) of the gate's NFT flavour to `recipient`. */
48
+ export declare function buildAirdropTx(ctx: GateAdminContext, recipient: string): Transaction;
49
+ /**
50
+ * Make the gate immutable — **irreversible**. Consumes the `AdminCap` (passed by value) and sets
51
+ * `Gate.frozen = true`, permanently ending all setters and `airdrop`. `purchase`/`consume` remain
52
+ * permissionless. Grant everything first, then freeze.
53
+ */
54
+ export declare function buildMakeGateImmutableTx(ctx: GateAdminContext): Transaction;
@@ -0,0 +1,11 @@
1
+ import type { Challenge } from './types.js';
2
+ /**
3
+ * Fetch a fresh challenge from a gateway's `GET /v1/challenge` endpoint. Tolerates both
4
+ * `expiresAt` (camelCase) and `expires_at` (snake_case) response shapes.
5
+ *
6
+ * @throws {Error} if the network request fails or the gateway returns a non-2xx status.
7
+ * @throws {Error} if the response body is missing the required `nonce` field.
8
+ */
9
+ export declare function fetchChallenge(gatewayHost: string, opts?: {
10
+ signal?: AbortSignal;
11
+ }): Promise<Challenge>;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * `@meddleware/nft-gate-client` — client-side helpers for the `access_gate` primitive.
3
+ *
4
+ * Client-side only: ownership queries, purchase/consume PTB builders, challenge signing,
5
+ * and access-proof assembly. Server-side verification lives in the Rust gateway.
6
+ */
7
+ export type { AccessGateConfig, GateAdminContext, OwnedGate, Challenge, AccessProof, OwnedAccessNft, OwnedObjectsClient, SuiObjectClient, } from './types.js';
8
+ export { fetchAccessNfts, ownsAccessNft, parseOwnedAccessNft, fetchAccessNftById, parseAdminCap, parseGate, fetchAdminCaps, fetchGate, fetchOwnedGates, } from './ownership.js';
9
+ export { buildPurchaseTx, buildConsumeTx, buildCreateGateTx, buildSetPriceTx, buildSetPaymentRecipientTx, buildSetPausedTx, buildSetDefaultUsesTx, buildSetSoulboundTx, buildSetAutoBurnAtZeroTx, buildSetNftNameTx, buildSetNftImageUrlTx, buildSetNftDescriptionTx, buildAirdropTx, buildMakeGateImmutableTx, } from './ptb.js';
10
+ export { fetchChallenge } from './challenge.js';
11
+ export { personalMessageForNonce, encodeAccessProof, decodeAccessProof, buildAccessProof, } from './proof.js';
12
+ export type { PersonalMessageSigner } from './proof.js';
@@ -0,0 +1,69 @@
1
+ import type { OwnedAccessNft, OwnedGate, OwnedObjectsClient, SuiObjectClient } from './types.js';
2
+ /**
3
+ * Parse a single `getOwnedObjects`/`getObject` entry into an {@link OwnedAccessNft}, or `null`
4
+ * if it is not an access NFT. Validates the object **type** when present (typed), and reads the
5
+ * nested `data.fields` deterministically.
6
+ */
7
+ export declare function parseOwnedAccessNft(entry: any): OwnedAccessNft | null;
8
+ /**
9
+ * Typed single-object read of one access NFT by id (`getObject` with `showType`+`showContent`),
10
+ * used when a UI needs the **exact** `usesRemaining` reliably rather than the best-effort parse
11
+ * of an owned-objects page. Returns `null` if the object is missing or not an access NFT.
12
+ *
13
+ * @throws {Error} if the RPC call fails at the network or transport layer.
14
+ */
15
+ export declare function fetchAccessNftById(client: SuiObjectClient, objectId: string): Promise<OwnedAccessNft | null>;
16
+ /**
17
+ * Fetch all access NFTs of `nftType` owned by `owner`, optionally restricted to a specific
18
+ * `gateId`. Uses `getOwnedObjects` filtered by `StructType` (the standard owned-objects query).
19
+ *
20
+ * @throws {Error} if the RPC call fails at the network or transport layer.
21
+ */
22
+ export declare function fetchAccessNfts(client: OwnedObjectsClient, owner: string, nftType: string, gateId?: string): Promise<OwnedAccessNft[]>;
23
+ /**
24
+ * True if `owner` holds at least one access NFT of `nftType` (optionally for `gateId`).
25
+ * This is the cheap check a frontend runs to decide whether to show a gated option, and a
26
+ * gateway runs (server-side) as part of access verification.
27
+ *
28
+ * @throws {Error} if the underlying RPC call fails.
29
+ */
30
+ export declare function ownsAccessNft(client: OwnedObjectsClient, owner: string, nftType: string, gateId?: string): Promise<boolean>;
31
+ /**
32
+ * Parse a single `getOwnedObjects`/`getObject` entry into `{ adminCapId, gateId }`, or `null` if
33
+ * it is not an `AdminCap`. Validates the object **type** when present and reads `fields.gate_id`.
34
+ */
35
+ export declare function parseAdminCap(entry: any): {
36
+ adminCapId: string;
37
+ gateId: string;
38
+ } | null;
39
+ /**
40
+ * Parse a `getObject` entry for a `Gate` shared object into an {@link OwnedGate} (minus
41
+ * `adminCapId`, which comes from the owning cap). Returns `null` if the object is missing its
42
+ * expected `Gate` fields.
43
+ */
44
+ export declare function parseGate(entry: any): Omit<OwnedGate, 'adminCapId'> | null;
45
+ /**
46
+ * List the `{ adminCapId, gateId }` pairs for every `access_gate::AdminCap` owned by `owner`
47
+ * under `packageId`. Uses `getOwnedObjects` filtered by `StructType` (the standard query).
48
+ *
49
+ * @throws {Error} if the underlying RPC call fails.
50
+ */
51
+ export declare function fetchAdminCaps(client: OwnedObjectsClient, owner: string, packageId: string): Promise<{
52
+ adminCapId: string;
53
+ gateId: string;
54
+ }[]>;
55
+ /**
56
+ * Typed single-object read of one `Gate` by id, returning its parsed state (without `adminCapId`).
57
+ * Returns `null` if the object is missing or not a `Gate`.
58
+ *
59
+ * @throws {Error} if the RPC call fails at the network or transport layer.
60
+ */
61
+ export declare function fetchGate(client: SuiObjectClient, gateId: string): Promise<Omit<OwnedGate, 'adminCapId'> | null>;
62
+ /**
63
+ * Fetch every gate `owner` administers: list their owned `AdminCap`s, then fetch each referenced
64
+ * `Gate` shared object and merge in the owning `adminCapId`. Gates whose object can no longer be
65
+ * read (e.g. deleted) are skipped.
66
+ *
67
+ * @throws {Error} if an underlying RPC call fails at the network or transport layer.
68
+ */
69
+ export declare function fetchOwnedGates(client: OwnedObjectsClient & SuiObjectClient, owner: string, packageId: string): Promise<OwnedGate[]>;
@@ -0,0 +1,27 @@
1
+ import type { AccessProof, Challenge } from './types.js';
2
+ /**
3
+ * The exact bytes a wallet signs (as a personal message) to answer a challenge. Both the
4
+ * client (signing) and the gateway (verifying) MUST derive the message identically.
5
+ */
6
+ export declare function personalMessageForNonce(nonce: string): Uint8Array;
7
+ /** Encode a proof as the compact Bearer token carried in the relay auth header. */
8
+ export declare function encodeAccessProof(proof: AccessProof): string;
9
+ /** Decode a proof token produced by {@link encodeAccessProof}. Throws on malformed input. */
10
+ export declare function decodeAccessProof(token: string): AccessProof;
11
+ /** A wallet-provided personal-message signer (e.g. wallet-standard `sui:signPersonalMessage`). */
12
+ export type PersonalMessageSigner = (message: Uint8Array) => Promise<{
13
+ signature: string;
14
+ }>;
15
+ /**
16
+ * Sign a challenge and assemble the encoded access-proof token to hand to any gateway as its
17
+ * auth bearer (e.g. an upload-relay client's auth-token option, an `Authorization` header).
18
+ *
19
+ * @throws {Error} if the wallet signer rejects or fails to sign the message.
20
+ */
21
+ export declare function buildAccessProof(opts: {
22
+ address: string;
23
+ challenge: Challenge;
24
+ sign: PersonalMessageSigner;
25
+ /** Present for single-use gates: the `consume` tx digest. */
26
+ consumeDigest?: string;
27
+ }): Promise<string>;
@@ -0,0 +1,54 @@
1
+ import { Transaction } from '@mysten/sui/transactions';
2
+ import type { AccessGateConfig, GateAdminContext } from './types.js';
3
+ /**
4
+ * Build a PTB that purchases access: split `priceMist` from the gas coin and call
5
+ * `access_gate::purchase(gate, payment)`. Overpayment is refunded on-chain, so the split
6
+ * must be exactly the price. The caller signs + executes with their wallet.
7
+ */
8
+ export declare function buildPurchaseTx(cfg: AccessGateConfig, priceMist: bigint | number): Transaction;
9
+ /**
10
+ * Build a PTB that consumes one use of a single-use NFT, binding it to `nonce`. Selects
11
+ * `consume` or `consume_soulbound` from `cfg.soulbound`. For unlimited passes there is
12
+ * nothing to consume — do not call this.
13
+ */
14
+ export declare function buildConsumeTx(cfg: AccessGateConfig, nftId: string, nonce: string): Transaction;
15
+ /**
16
+ * Build a PTB that creates a new gate. Mostly for tooling/operators; the frontend usually
17
+ * only purchases/consumes an existing gate.
18
+ */
19
+ export declare function buildCreateGateTx(packageId: string, opts: {
20
+ priceMist: bigint | number;
21
+ paymentRecipient: string;
22
+ defaultUses: bigint | number;
23
+ soulbound: boolean;
24
+ autoBurnAtZero: boolean;
25
+ nftName: string;
26
+ nftImageUrl: string;
27
+ nftDescription: string;
28
+ }): Transaction;
29
+ /** Set the gate price (in MIST) charged by future `purchase` calls (0 = free). */
30
+ export declare function buildSetPriceTx(ctx: GateAdminContext, priceMist: bigint | number): Transaction;
31
+ /** Redirect future purchase payments to a new recipient address. */
32
+ export declare function buildSetPaymentRecipientTx(ctx: GateAdminContext, recipient: string): Transaction;
33
+ /** Pause or unpause `purchase` (paused ⇒ `purchase` aborts with `E_PAUSED`). */
34
+ export declare function buildSetPausedTx(ctx: GateAdminContext, paused: boolean): Transaction;
35
+ /** Change the default uses for future mints (0 ⇒ unlimited pass; N ⇒ single-use with N). */
36
+ export declare function buildSetDefaultUsesTx(ctx: GateAdminContext, defaultUses: bigint | number): Transaction;
37
+ /** Switch the soulbound flag for future mints (does not affect already-minted NFTs). */
38
+ export declare function buildSetSoulboundTx(ctx: GateAdminContext, soulbound: boolean): Transaction;
39
+ /** Toggle the auto-burn-at-zero policy for future mints. */
40
+ export declare function buildSetAutoBurnAtZeroTx(ctx: GateAdminContext, autoBurn: boolean): Transaction;
41
+ /** Update the default NFT display name for future mints. */
42
+ export declare function buildSetNftNameTx(ctx: GateAdminContext, name: string): Transaction;
43
+ /** Update the default NFT image URL for future mints. */
44
+ export declare function buildSetNftImageUrlTx(ctx: GateAdminContext, url: string): Transaction;
45
+ /** Update the default NFT description for future mints. */
46
+ export declare function buildSetNftDescriptionTx(ctx: GateAdminContext, description: string): Transaction;
47
+ /** AdminCap-gated free grant (airdrop) of the gate's NFT flavour to `recipient`. */
48
+ export declare function buildAirdropTx(ctx: GateAdminContext, recipient: string): Transaction;
49
+ /**
50
+ * Make the gate immutable — **irreversible**. Consumes the `AdminCap` (passed by value) and sets
51
+ * `Gate.frozen = true`, permanently ending all setters and `airdrop`. `purchase`/`consume` remain
52
+ * permissionless. Grant everything first, then freeze.
53
+ */
54
+ export declare function buildMakeGateImmutableTx(ctx: GateAdminContext): Transaction;
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Shared wire + config types for the access-gate client.
3
+ *
4
+ * These mirror the on-chain `access_gate` Move package and the challenge/proof wire
5
+ * protocol implemented by the generic Rust gateway. Keep the three in sync.
6
+ */
7
+ /** Identifies a deployed gate and the NFT type that satisfies it. */
8
+ export interface AccessGateConfig {
9
+ /** Published `access_gate` package ID. */
10
+ packageId: string;
11
+ /** The shared `Gate` object ID. */
12
+ gateId: string;
13
+ /** The shared `PlatformConfig` object ID. Required for `buildPurchaseTx`. */
14
+ platformConfigId: string;
15
+ /**
16
+ * Fully-qualified NFT type string to filter ownership by, e.g.
17
+ * `<pkg>::access_gate::AccessNFT` or `<pkg>::access_gate::SoulboundAccessNFT`.
18
+ * Choose the variant matching the gate's `soulbound` flag.
19
+ */
20
+ nftType: string;
21
+ /** Whether this gate mints soulbound NFTs (selects `consume` vs `consume_soulbound`). */
22
+ soulbound?: boolean;
23
+ }
24
+ /**
25
+ * Identifies a gate an operator administers, for the AdminCap-gated management PTB builders
26
+ * (setters, airdrop, freeze). The three ids together authorise a call: `adminCapId` must be the
27
+ * `AdminCap` whose `gate_id` matches `gateId`, under the published `packageId`.
28
+ */
29
+ export interface GateAdminContext {
30
+ /** Published `access_gate` package ID. */
31
+ packageId: string;
32
+ /** The shared `Gate` object ID being administered. */
33
+ gateId: string;
34
+ /** The `AdminCap` object ID authorised over `gateId` (held by the operator). */
35
+ adminCapId: string;
36
+ }
37
+ /** A gate an operator administers, parsed from its on-chain `Gate` object + owning `AdminCap`. */
38
+ export interface OwnedGate {
39
+ /** The shared `Gate` object ID. */
40
+ gateId: string;
41
+ /** The `AdminCap` object ID that authorises administering this gate. */
42
+ adminCapId: string;
43
+ /** Price in MIST charged by `purchase` (0 = free). */
44
+ priceMist: bigint;
45
+ /** Address that receives the operator share of each paid `purchase`. */
46
+ paymentRecipient: string;
47
+ /** 0 ⇒ unlimited passes; N ⇒ single-use NFTs with N uses. */
48
+ defaultUses: bigint;
49
+ /** Whether newly-minted NFTs are soulbound. */
50
+ soulbound: boolean;
51
+ /** Whether a single-use NFT is deleted (vs. kept as a receipt) at zero uses. */
52
+ autoBurnAtZero: boolean;
53
+ /** Whether `purchase` is currently disabled. */
54
+ paused: boolean;
55
+ /** Whether the gate has been made immutable (all admin/airdrop permanently disabled). */
56
+ frozen: boolean;
57
+ /** Default NFT display name minted into future NFTs. */
58
+ nftName: string;
59
+ /** Default NFT image URL minted into future NFTs. */
60
+ nftImageUrl: string;
61
+ /** Default NFT description minted into future NFTs. */
62
+ nftDescription: string;
63
+ }
64
+ /** A server-issued, time-bound challenge the wallet signs to prove control of an address. */
65
+ export interface Challenge {
66
+ /** Opaque nonce (as issued by the gateway; treated as a UTF-8 string end-to-end). */
67
+ nonce: string;
68
+ /** Unix epoch milliseconds after which the challenge is rejected. */
69
+ expiresAt: number;
70
+ }
71
+ /** The proof a client presents to a gateway to demonstrate gated access. */
72
+ export interface AccessProof {
73
+ /** The Sui address claimed by the caller. */
74
+ address: string;
75
+ /** The challenge nonce that was signed. */
76
+ nonce: string;
77
+ /** Base64 personal-message signature over {@link personalMessageForNonce}. */
78
+ signature: string;
79
+ /**
80
+ * For single-use gates: the digest of the on-chain `consume(nft, nonce)` transaction, so
81
+ * the gateway can confirm the matching `AccessConsumedEvent` before allowing the request.
82
+ */
83
+ consumeDigest?: string;
84
+ }
85
+ /** A parsed owned access NFT. */
86
+ export interface OwnedAccessNft {
87
+ objectId: string;
88
+ gateId: string;
89
+ /** `null` for an unlimited pass; otherwise remaining single-use count. */
90
+ usesRemaining: number | null;
91
+ }
92
+ /** Minimal structural subset of a Sui client used for ownership queries (grpc or json-rpc). */
93
+ export interface OwnedObjectsClient {
94
+ getOwnedObjects(params: {
95
+ owner: string;
96
+ filter?: {
97
+ StructType: string;
98
+ };
99
+ options?: {
100
+ showContent?: boolean;
101
+ showType?: boolean;
102
+ };
103
+ cursor?: string | null;
104
+ limit?: number | null;
105
+ }): Promise<{
106
+ data: unknown[];
107
+ hasNextPage?: boolean;
108
+ nextCursor?: string | null;
109
+ }>;
110
+ }
111
+ /** Minimal structural subset of a Sui client used for a typed single-object read. */
112
+ export interface SuiObjectClient {
113
+ getObject(params: {
114
+ id: string;
115
+ options?: {
116
+ showContent?: boolean;
117
+ showType?: boolean;
118
+ };
119
+ }): Promise<unknown>;
120
+ }
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Shared wire + config types for the access-gate client.
3
+ *
4
+ * These mirror the on-chain `access_gate` Move package and the challenge/proof wire
5
+ * protocol implemented by the generic Rust gateway. Keep the three in sync.
6
+ */
7
+ /** Identifies a deployed gate and the NFT type that satisfies it. */
8
+ export interface AccessGateConfig {
9
+ /** Published `access_gate` package ID. */
10
+ packageId: string;
11
+ /** The shared `Gate` object ID. */
12
+ gateId: string;
13
+ /** The shared `PlatformConfig` object ID. Required for `buildPurchaseTx`. */
14
+ platformConfigId: string;
15
+ /**
16
+ * Fully-qualified NFT type string to filter ownership by, e.g.
17
+ * `<pkg>::access_gate::AccessNFT` or `<pkg>::access_gate::SoulboundAccessNFT`.
18
+ * Choose the variant matching the gate's `soulbound` flag.
19
+ */
20
+ nftType: string;
21
+ /** Whether this gate mints soulbound NFTs (selects `consume` vs `consume_soulbound`). */
22
+ soulbound?: boolean;
23
+ }
24
+ /**
25
+ * Identifies a gate an operator administers, for the AdminCap-gated management PTB builders
26
+ * (setters, airdrop, freeze). The three ids together authorise a call: `adminCapId` must be the
27
+ * `AdminCap` whose `gate_id` matches `gateId`, under the published `packageId`.
28
+ */
29
+ export interface GateAdminContext {
30
+ /** Published `access_gate` package ID. */
31
+ packageId: string;
32
+ /** The shared `Gate` object ID being administered. */
33
+ gateId: string;
34
+ /** The `AdminCap` object ID authorised over `gateId` (held by the operator). */
35
+ adminCapId: string;
36
+ }
37
+ /** A gate an operator administers, parsed from its on-chain `Gate` object + owning `AdminCap`. */
38
+ export interface OwnedGate {
39
+ /** The shared `Gate` object ID. */
40
+ gateId: string;
41
+ /** The `AdminCap` object ID that authorises administering this gate. */
42
+ adminCapId: string;
43
+ /** Price in MIST charged by `purchase` (0 = free). */
44
+ priceMist: bigint;
45
+ /** Address that receives the operator share of each paid `purchase`. */
46
+ paymentRecipient: string;
47
+ /** 0 ⇒ unlimited passes; N ⇒ single-use NFTs with N uses. */
48
+ defaultUses: bigint;
49
+ /** Whether newly-minted NFTs are soulbound. */
50
+ soulbound: boolean;
51
+ /** Whether a single-use NFT is deleted (vs. kept as a receipt) at zero uses. */
52
+ autoBurnAtZero: boolean;
53
+ /** Whether `purchase` is currently disabled. */
54
+ paused: boolean;
55
+ /** Whether the gate has been made immutable (all admin/airdrop permanently disabled). */
56
+ frozen: boolean;
57
+ /** Default NFT display name minted into future NFTs. */
58
+ nftName: string;
59
+ /** Default NFT image URL minted into future NFTs. */
60
+ nftImageUrl: string;
61
+ /** Default NFT description minted into future NFTs. */
62
+ nftDescription: string;
63
+ }
64
+ /** A server-issued, time-bound challenge the wallet signs to prove control of an address. */
65
+ export interface Challenge {
66
+ /** Opaque nonce (as issued by the gateway; treated as a UTF-8 string end-to-end). */
67
+ nonce: string;
68
+ /** Unix epoch milliseconds after which the challenge is rejected. */
69
+ expiresAt: number;
70
+ }
71
+ /** The proof a client presents to a gateway to demonstrate gated access. */
72
+ export interface AccessProof {
73
+ /** The Sui address claimed by the caller. */
74
+ address: string;
75
+ /** The challenge nonce that was signed. */
76
+ nonce: string;
77
+ /** Base64 personal-message signature over {@link personalMessageForNonce}. */
78
+ signature: string;
79
+ /**
80
+ * For single-use gates: the digest of the on-chain `consume(nft, nonce)` transaction, so
81
+ * the gateway can confirm the matching `AccessConsumedEvent` before allowing the request.
82
+ */
83
+ consumeDigest?: string;
84
+ }
85
+ /** A parsed owned access NFT. */
86
+ export interface OwnedAccessNft {
87
+ objectId: string;
88
+ gateId: string;
89
+ /** `null` for an unlimited pass; otherwise remaining single-use count. */
90
+ usesRemaining: number | null;
91
+ }
92
+ /** Minimal structural subset of a Sui client used for ownership queries (grpc or json-rpc). */
93
+ export interface OwnedObjectsClient {
94
+ getOwnedObjects(params: {
95
+ owner: string;
96
+ filter?: {
97
+ StructType: string;
98
+ };
99
+ options?: {
100
+ showContent?: boolean;
101
+ showType?: boolean;
102
+ };
103
+ cursor?: string | null;
104
+ limit?: number | null;
105
+ }): Promise<{
106
+ data: unknown[];
107
+ hasNextPage?: boolean;
108
+ nextCursor?: string | null;
109
+ }>;
110
+ }
111
+ /** Minimal structural subset of a Sui client used for a typed single-object read. */
112
+ export interface SuiObjectClient {
113
+ getObject(params: {
114
+ id: string;
115
+ options?: {
116
+ showContent?: boolean;
117
+ showType?: boolean;
118
+ };
119
+ }): Promise<unknown>;
120
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meddleware/nft-gate-client",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "description": "Client-side helpers for the access_gate NFT access primitive: ownership queries, purchase/consume PTB builders, challenge signing, and access-proof assembly.",
6
6
  "author": "MeddleWare <meddleware@proton.me>",
@@ -18,15 +18,18 @@
18
18
  ],
19
19
  "files": [
20
20
  "src",
21
+ "dist",
21
22
  "CHANGELOG.md"
22
23
  ],
23
24
  "exports": {
24
25
  ".": {
25
- "types": "./src/index.ts",
26
+ "types": "./dist/index.d.ts",
26
27
  "default": "./src/index.ts"
27
28
  }
28
29
  },
29
30
  "scripts": {
31
+ "build": "tsc -p tsconfig.build.json",
32
+ "prepublishOnly": "npm run build",
30
33
  "type-check": "tsc --noEmit",
31
34
  "test": "vitest run",
32
35
  "test:watch": "vitest"
@@ -42,4 +45,4 @@
42
45
  "publishConfig": {
43
46
  "access": "public"
44
47
  }
45
- }
48
+ }