@meddleware/nft-gate-client 0.0.5 → 0.0.7
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/index.d.ts +1 -1
- package/dist/ownership.d.ts +3 -3
- package/dist/types.d.ts +37 -25
- package/package.json +5 -4
- package/src/index.ts +1 -0
- package/src/ownership.ts +38 -28
- package/src/types.ts +25 -13
- package/dist/src/challenge.d.ts +0 -11
- package/dist/src/index.d.ts +0 -12
- package/dist/src/ownership.d.ts +0 -69
- package/dist/src/proof.d.ts +0 -27
- package/dist/src/ptb.d.ts +0 -54
- package/dist/src/types.d.ts +0 -120
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Client-side only: ownership queries, purchase/consume PTB builders, challenge signing,
|
|
5
5
|
* and access-proof assembly. Server-side verification lives in the Rust gateway.
|
|
6
6
|
*/
|
|
7
|
-
export type { AccessGateConfig, GateAdminContext, OwnedGate, Challenge, AccessProof, OwnedAccessNft, OwnedObjectsClient, SuiObjectClient, } from './types.js';
|
|
7
|
+
export type { AccessGateConfig, CoreObject, GateAdminContext, OwnedGate, Challenge, AccessProof, OwnedAccessNft, OwnedObjectsClient, SuiObjectClient, } from './types.js';
|
|
8
8
|
export { fetchAccessNfts, ownsAccessNft, parseOwnedAccessNft, fetchAccessNftById, parseAdminCap, parseGate, fetchAdminCaps, fetchGate, fetchOwnedGates, } from './ownership.js';
|
|
9
9
|
export { buildPurchaseTx, buildConsumeTx, buildCreateGateTx, buildSetPriceTx, buildSetPaymentRecipientTx, buildSetPausedTx, buildSetDefaultUsesTx, buildSetSoulboundTx, buildSetAutoBurnAtZeroTx, buildSetNftNameTx, buildSetNftImageUrlTx, buildSetNftDescriptionTx, buildAirdropTx, buildMakeGateImmutableTx, } from './ptb.js';
|
|
10
10
|
export { fetchChallenge } from './challenge.js';
|
package/dist/ownership.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { OwnedAccessNft, OwnedGate, OwnedObjectsClient, SuiObjectClient } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Parse a single `
|
|
4
|
-
* if it is not an access NFT. Validates the object **type**
|
|
5
|
-
* nested `data
|
|
3
|
+
* Parse a single core-API object (a `listOwnedObjects` item or a `getObject`'s `{ object }`) into
|
|
4
|
+
* an {@link OwnedAccessNft}, or `null` if it is not an access NFT. Validates the object **type**
|
|
5
|
+
* when present (typed), and reads the nested `data` fields deterministically.
|
|
6
6
|
*/
|
|
7
7
|
export declare function parseOwnedAccessNft(entry: any): OwnedAccessNft | null;
|
|
8
8
|
/**
|
package/dist/types.d.ts
CHANGED
|
@@ -89,32 +89,44 @@ export interface OwnedAccessNft {
|
|
|
89
89
|
/** `null` for an unlimited pass; otherwise remaining single-use count. */
|
|
90
90
|
usesRemaining: number | null;
|
|
91
91
|
}
|
|
92
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* A single owned/read object as returned by the unified core API (`SuiGrpcClient`): the id and
|
|
94
|
+
* Move struct type are top-level; the struct fields come back under `json` (opt-in). Kept as a
|
|
95
|
+
* structural subset so any client exposing the core API satisfies it without importing the SDK.
|
|
96
|
+
*/
|
|
97
|
+
export interface CoreObject {
|
|
98
|
+
objectId: string;
|
|
99
|
+
type?: string;
|
|
100
|
+
json?: Record<string, unknown> | null;
|
|
101
|
+
}
|
|
102
|
+
/** Minimal structural subset of a core Sui client used for owned-object listing (`SuiGrpcClient`). */
|
|
93
103
|
export interface OwnedObjectsClient {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}>;
|
|
104
|
+
core: {
|
|
105
|
+
listOwnedObjects(options: {
|
|
106
|
+
owner: string;
|
|
107
|
+
type?: string;
|
|
108
|
+
cursor?: string | null;
|
|
109
|
+
limit?: number;
|
|
110
|
+
include?: {
|
|
111
|
+
json?: boolean;
|
|
112
|
+
};
|
|
113
|
+
}): Promise<{
|
|
114
|
+
objects: CoreObject[];
|
|
115
|
+
hasNextPage: boolean;
|
|
116
|
+
cursor: string | null;
|
|
117
|
+
}>;
|
|
118
|
+
};
|
|
110
119
|
}
|
|
111
|
-
/** Minimal structural subset of a Sui client used for a typed single-object read. */
|
|
120
|
+
/** Minimal structural subset of a core Sui client used for a typed single-object read. */
|
|
112
121
|
export interface SuiObjectClient {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
122
|
+
core: {
|
|
123
|
+
getObject(options: {
|
|
124
|
+
objectId: string;
|
|
125
|
+
include?: {
|
|
126
|
+
json?: boolean;
|
|
127
|
+
};
|
|
128
|
+
}): Promise<{
|
|
129
|
+
object: CoreObject;
|
|
130
|
+
}>;
|
|
131
|
+
};
|
|
120
132
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meddleware/nft-gate-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
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>",
|
|
@@ -28,14 +28,15 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"scripts": {
|
|
31
|
-
"build": "tsc -p tsconfig.build.json",
|
|
31
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
32
32
|
"prepublishOnly": "npm run build",
|
|
33
33
|
"type-check": "tsc --noEmit",
|
|
34
34
|
"test": "vitest run",
|
|
35
|
-
"test:watch": "vitest"
|
|
35
|
+
"test:watch": "vitest",
|
|
36
|
+
"test:integration": "vitest run --config vitest.integration.config.ts"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"@mysten/sui": "
|
|
39
|
+
"@mysten/sui": "^2.28.0"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@types/node": "~24.12.2",
|
package/src/index.ts
CHANGED
package/src/ownership.ts
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
|
-
import type { OwnedAccessNft, OwnedGate, OwnedObjectsClient, SuiObjectClient } from './types.js'
|
|
1
|
+
import type { CoreObject, OwnedAccessNft, OwnedGate, OwnedObjectsClient, SuiObjectClient } from './types.js'
|
|
2
2
|
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Unwrap a Move-struct field bag from a core `json` value. The gRPC/core API returns struct
|
|
7
|
+
* fields flat; the old JSON-RPC shape nested them under `.fields`. Tolerate both so parsing is
|
|
8
|
+
* robust to the transport and to the SDK's documented caveat that the `json` shape may vary.
|
|
9
|
+
*/
|
|
10
|
+
function structFields(v: unknown): Record<string, any> | undefined {
|
|
11
|
+
if (!v || typeof v !== 'object') return undefined
|
|
12
|
+
const o = v as Record<string, any>
|
|
13
|
+
const nested = o.fields
|
|
14
|
+
return nested && typeof nested === 'object' ? (nested as Record<string, any>) : o
|
|
15
|
+
}
|
|
16
|
+
|
|
5
17
|
/**
|
|
6
18
|
* Extract `uses_remaining` from a Move enum `AccessVariant` as rendered by RPC, driven by the
|
|
7
19
|
* enum **variant tag** (typed) rather than guessing from field presence. Sui renders a Move
|
|
@@ -25,18 +37,18 @@ function isAccessNftType(type: unknown): boolean {
|
|
|
25
37
|
}
|
|
26
38
|
|
|
27
39
|
/**
|
|
28
|
-
* Parse a single `
|
|
29
|
-
* if it is not an access NFT. Validates the object **type**
|
|
30
|
-
* nested `data
|
|
40
|
+
* Parse a single core-API object (a `listOwnedObjects` item or a `getObject`'s `{ object }`) into
|
|
41
|
+
* an {@link OwnedAccessNft}, or `null` if it is not an access NFT. Validates the object **type**
|
|
42
|
+
* when present (typed), and reads the nested `data` fields deterministically.
|
|
31
43
|
*/
|
|
32
44
|
export function parseOwnedAccessNft(entry: any): OwnedAccessNft | null {
|
|
33
|
-
const obj = entry?.
|
|
34
|
-
const objectId: string | undefined = obj?.objectId
|
|
35
|
-
const type: unknown = obj?.type
|
|
45
|
+
const obj: CoreObject | undefined = entry?.object ?? entry
|
|
46
|
+
const objectId: string | undefined = obj?.objectId
|
|
47
|
+
const type: unknown = obj?.type
|
|
36
48
|
// When the type is present it MUST be an access NFT; when absent (some node shapes) fall back
|
|
37
49
|
// to structural checks below.
|
|
38
50
|
if (type !== undefined && !isAccessNftType(type)) return null
|
|
39
|
-
const inner = obj?.
|
|
51
|
+
const inner = structFields(structFields(obj?.json)?.data)
|
|
40
52
|
const gateId: string | undefined = inner?.gate_id ?? inner?.gateId
|
|
41
53
|
if (!objectId || !gateId) return null
|
|
42
54
|
return {
|
|
@@ -57,10 +69,7 @@ export async function fetchAccessNftById(
|
|
|
57
69
|
client: SuiObjectClient,
|
|
58
70
|
objectId: string,
|
|
59
71
|
): Promise<OwnedAccessNft | null> {
|
|
60
|
-
const res = await client.getObject({
|
|
61
|
-
id: objectId,
|
|
62
|
-
options: { showType: true, showContent: true },
|
|
63
|
-
})
|
|
72
|
+
const res = await client.core.getObject({ objectId, include: { json: true } })
|
|
64
73
|
return parseOwnedAccessNft(res)
|
|
65
74
|
}
|
|
66
75
|
|
|
@@ -76,12 +85,12 @@ export async function fetchAccessNfts(
|
|
|
76
85
|
nftType: string,
|
|
77
86
|
gateId?: string,
|
|
78
87
|
): Promise<OwnedAccessNft[]> {
|
|
79
|
-
const {
|
|
88
|
+
const { objects } = await client.core.listOwnedObjects({
|
|
80
89
|
owner,
|
|
81
|
-
|
|
82
|
-
|
|
90
|
+
type: nftType,
|
|
91
|
+
include: { json: true },
|
|
83
92
|
})
|
|
84
|
-
const parsed = (
|
|
93
|
+
const parsed = (objects ?? [])
|
|
85
94
|
.map(parseOwnedAccessNft)
|
|
86
95
|
.filter((n): n is OwnedAccessNft => n !== null)
|
|
87
96
|
return gateId ? parsed.filter((n) => n.gateId === gateId) : parsed
|
|
@@ -118,11 +127,12 @@ function isAdminCapType(type: unknown): boolean {
|
|
|
118
127
|
* it is not an `AdminCap`. Validates the object **type** when present and reads `fields.gate_id`.
|
|
119
128
|
*/
|
|
120
129
|
export function parseAdminCap(entry: any): { adminCapId: string; gateId: string } | null {
|
|
121
|
-
const obj = entry?.
|
|
122
|
-
const adminCapId: string | undefined = obj?.objectId
|
|
123
|
-
const type: unknown = obj?.type
|
|
130
|
+
const obj: CoreObject | undefined = entry?.object ?? entry
|
|
131
|
+
const adminCapId: string | undefined = obj?.objectId
|
|
132
|
+
const type: unknown = obj?.type
|
|
124
133
|
if (type !== undefined && !isAdminCapType(type)) return null
|
|
125
|
-
const
|
|
134
|
+
const f = structFields(obj?.json)
|
|
135
|
+
const gateId: string | undefined = f?.gate_id ?? f?.gateId
|
|
126
136
|
if (!adminCapId || !gateId) return null
|
|
127
137
|
return { adminCapId, gateId }
|
|
128
138
|
}
|
|
@@ -133,9 +143,9 @@ export function parseAdminCap(entry: any): { adminCapId: string; gateId: string
|
|
|
133
143
|
* expected `Gate` fields.
|
|
134
144
|
*/
|
|
135
145
|
export function parseGate(entry: any): Omit<OwnedGate, 'adminCapId'> | null {
|
|
136
|
-
const obj = entry?.
|
|
137
|
-
const gateId: string | undefined = obj?.objectId
|
|
138
|
-
const f = obj?.
|
|
146
|
+
const obj: CoreObject | undefined = entry?.object ?? entry
|
|
147
|
+
const gateId: string | undefined = obj?.objectId
|
|
148
|
+
const f = structFields(obj?.json)
|
|
139
149
|
if (!gateId || !f) return null
|
|
140
150
|
return {
|
|
141
151
|
gateId,
|
|
@@ -163,12 +173,12 @@ export async function fetchAdminCaps(
|
|
|
163
173
|
owner: string,
|
|
164
174
|
packageId: string,
|
|
165
175
|
): Promise<{ adminCapId: string; gateId: string }[]> {
|
|
166
|
-
const {
|
|
176
|
+
const { objects } = await client.core.listOwnedObjects({
|
|
167
177
|
owner,
|
|
168
|
-
|
|
169
|
-
|
|
178
|
+
type: `${packageId}::access_gate::AdminCap`,
|
|
179
|
+
include: { json: true },
|
|
170
180
|
})
|
|
171
|
-
return (
|
|
181
|
+
return (objects ?? [])
|
|
172
182
|
.map(parseAdminCap)
|
|
173
183
|
.filter((c): c is { adminCapId: string; gateId: string } => c !== null)
|
|
174
184
|
}
|
|
@@ -183,7 +193,7 @@ export async function fetchGate(
|
|
|
183
193
|
client: SuiObjectClient,
|
|
184
194
|
gateId: string,
|
|
185
195
|
): Promise<Omit<OwnedGate, 'adminCapId'> | null> {
|
|
186
|
-
const res = await client.getObject({
|
|
196
|
+
const res = await client.core.getObject({ objectId: gateId, include: { json: true } })
|
|
187
197
|
return parseGate(res)
|
|
188
198
|
}
|
|
189
199
|
|
package/src/types.ts
CHANGED
|
@@ -96,21 +96,33 @@ export interface OwnedAccessNft {
|
|
|
96
96
|
usesRemaining: number | null
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
/**
|
|
99
|
+
/**
|
|
100
|
+
* A single owned/read object as returned by the unified core API (`SuiGrpcClient`): the id and
|
|
101
|
+
* Move struct type are top-level; the struct fields come back under `json` (opt-in). Kept as a
|
|
102
|
+
* structural subset so any client exposing the core API satisfies it without importing the SDK.
|
|
103
|
+
*/
|
|
104
|
+
export interface CoreObject {
|
|
105
|
+
objectId: string
|
|
106
|
+
type?: string
|
|
107
|
+
json?: Record<string, unknown> | null
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Minimal structural subset of a core Sui client used for owned-object listing (`SuiGrpcClient`). */
|
|
100
111
|
export interface OwnedObjectsClient {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
112
|
+
core: {
|
|
113
|
+
listOwnedObjects(options: {
|
|
114
|
+
owner: string
|
|
115
|
+
type?: string
|
|
116
|
+
cursor?: string | null
|
|
117
|
+
limit?: number
|
|
118
|
+
include?: { json?: boolean }
|
|
119
|
+
}): Promise<{ objects: CoreObject[]; hasNextPage: boolean; cursor: string | null }>
|
|
120
|
+
}
|
|
108
121
|
}
|
|
109
122
|
|
|
110
|
-
/** Minimal structural subset of a Sui client used for a typed single-object read. */
|
|
123
|
+
/** Minimal structural subset of a core Sui client used for a typed single-object read. */
|
|
111
124
|
export interface SuiObjectClient {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}): Promise<unknown>
|
|
125
|
+
core: {
|
|
126
|
+
getObject(options: { objectId: string; include?: { json?: boolean } }): Promise<{ object: CoreObject }>
|
|
127
|
+
}
|
|
116
128
|
}
|
package/dist/src/challenge.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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>;
|
package/dist/src/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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';
|
package/dist/src/ownership.d.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
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[]>;
|
package/dist/src/proof.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
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/src/ptb.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
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;
|
package/dist/src/types.d.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
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
|
-
}
|