@gesturegate/sdk 0.1.1 → 0.1.2
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 +21 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -16
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Address, type Hex, type PublicClient } from "viem";
|
|
2
2
|
export declare const monadTestnetChainId = 10143;
|
|
3
|
+
export declare const monadMainnetChainId = 143;
|
|
3
4
|
/** The official GestureGate deployment. Partners do not configure these values. */
|
|
4
5
|
export declare const gestureGateDeployments: {
|
|
5
6
|
readonly 10143: {
|
|
@@ -7,6 +8,11 @@ export declare const gestureGateDeployments: {
|
|
|
7
8
|
readonly apiOrigin: "https://gesturegate.vercel.app";
|
|
8
9
|
readonly registryAddress: Address;
|
|
9
10
|
};
|
|
11
|
+
readonly 143: {
|
|
12
|
+
readonly chainId: 143;
|
|
13
|
+
readonly apiOrigin: "https://gesturegate.vercel.app";
|
|
14
|
+
readonly registryAddress: Address;
|
|
15
|
+
};
|
|
10
16
|
};
|
|
11
17
|
export type GestureGateDeployment = {
|
|
12
18
|
chainId: number;
|
|
@@ -14,11 +20,15 @@ export type GestureGateDeployment = {
|
|
|
14
20
|
registryAddress: Address;
|
|
15
21
|
};
|
|
16
22
|
export declare function getGestureGateDeployment(chainId: number): GestureGateDeployment | undefined;
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
export type GestureGateIntentDomain = {
|
|
24
|
+
name: "GestureGate";
|
|
25
|
+
version: "1";
|
|
26
|
+
chainId: number;
|
|
21
27
|
};
|
|
28
|
+
/** Builds an EIP-712 domain that is bound to the chain being verified. */
|
|
29
|
+
export declare function getGestureGateIntentDomain(chainId: number): GestureGateIntentDomain;
|
|
30
|
+
/** Testnet compatibility export. New integrations select the domain by chain. */
|
|
31
|
+
export declare const gestureGateIntentDomain: GestureGateIntentDomain;
|
|
22
32
|
export declare const gestureGateIntentTypes: {
|
|
23
33
|
readonly GateIntent: readonly [{
|
|
24
34
|
readonly name: "subject";
|
|
@@ -53,7 +63,7 @@ export declare const gestureGateRegistryAbi: readonly [{
|
|
|
53
63
|
}];
|
|
54
64
|
}];
|
|
55
65
|
export type SignTypedData = (args: {
|
|
56
|
-
domain:
|
|
66
|
+
domain: GestureGateIntentDomain;
|
|
57
67
|
types: typeof gestureGateIntentTypes;
|
|
58
68
|
primaryType: "GateIntent";
|
|
59
69
|
message: {
|
|
@@ -69,6 +79,7 @@ export type HostedStart = {
|
|
|
69
79
|
expiresAt: string;
|
|
70
80
|
transactionHash: Hex;
|
|
71
81
|
verifyUrl: string;
|
|
82
|
+
chainId: number;
|
|
72
83
|
};
|
|
73
84
|
export type HostedVerifiedMessage = {
|
|
74
85
|
type: "gesturegate:verified";
|
|
@@ -94,13 +105,16 @@ export type EnsureVerifiedOptions = VerificationCheck & {
|
|
|
94
105
|
export type GestureGateClientOptions = Omit<VerificationCheck, "address" | "ttlSeconds"> & {
|
|
95
106
|
projectId: string;
|
|
96
107
|
defaultTtlSeconds: number;
|
|
108
|
+
/** Per-chain deployments, useful while a Mainnet deployment is being configured. */
|
|
109
|
+
deployments?: Partial<Record<number, GestureGateDeployment>>;
|
|
97
110
|
};
|
|
98
|
-
export declare function createChallengeIntent(subject: Address, projectId: string, signTypedData: SignTypedData, now?: number): Promise<{
|
|
111
|
+
export declare function createChallengeIntent(subject: Address, projectId: string, signTypedData: SignTypedData, now?: number, chainId?: number): Promise<{
|
|
99
112
|
subject: `0x${string}`;
|
|
100
113
|
projectId: string;
|
|
101
114
|
nonce: `0x${string}`;
|
|
102
115
|
expiresAt: string;
|
|
103
116
|
signature: `0x${string}`;
|
|
117
|
+
chainId: number;
|
|
104
118
|
}>;
|
|
105
119
|
export declare function startHostedVerification(options: {
|
|
106
120
|
projectId: string;
|
|
@@ -112,6 +126,7 @@ export declare function startHostedVerification(options: {
|
|
|
112
126
|
expiresAt: string;
|
|
113
127
|
transactionHash: `0x${string}`;
|
|
114
128
|
verifyUrl: string;
|
|
129
|
+
chainId: number;
|
|
115
130
|
}>;
|
|
116
131
|
export declare function isVerifiedWithin(options: VerificationCheck): Promise<boolean>;
|
|
117
132
|
/** Returns an explicit address-bound status for application UI and guards. */
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,YAAY,EAAE,MAAM,MAAM,CAAC;AAEnF,eAAO,MAAM,mBAAmB,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,YAAY,EAAE,MAAM,MAAM,CAAC;AAEnF,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AACzC,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC,mFAAmF;AACnF,eAAO,MAAM,sBAAsB;;;;kCAIkC,OAAO;;;;;kCAKP,OAAO;;CAElE,CAAC;AAEX,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAE3F;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,GAAG,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,0EAA0E;AAC1E,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,uBAAuB,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O,EAAE,qBAAqB;;;;;;;;GAUlE;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,wBAAwB;qBAWzC,OAAO;kBAQf;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,aAAa,EAAE,aAAa,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE;4BAKpF;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,aAAa,EAAE,aAAa,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE;;;;;;;;;GAQpJ"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { keccak256, toHex } from "viem";
|
|
2
2
|
export const monadTestnetChainId = 10143;
|
|
3
|
+
export const monadMainnetChainId = 143;
|
|
3
4
|
/** The official GestureGate deployment. Partners do not configure these values. */
|
|
4
5
|
export const gestureGateDeployments = {
|
|
5
6
|
[monadTestnetChainId]: {
|
|
@@ -7,15 +8,21 @@ export const gestureGateDeployments = {
|
|
|
7
8
|
apiOrigin: "https://gesturegate.vercel.app",
|
|
8
9
|
registryAddress: "0x0B8a46b6c46a37B8B91C78D3f73549747e2027e3",
|
|
9
10
|
},
|
|
11
|
+
[monadMainnetChainId]: {
|
|
12
|
+
chainId: monadMainnetChainId,
|
|
13
|
+
apiOrigin: "https://gesturegate.vercel.app",
|
|
14
|
+
registryAddress: "0xaa280c0502A36E311aa7d301F0Bf997691b06968",
|
|
15
|
+
},
|
|
10
16
|
};
|
|
11
17
|
export function getGestureGateDeployment(chainId) {
|
|
12
18
|
return gestureGateDeployments[chainId];
|
|
13
19
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
version: "1",
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
/** Builds an EIP-712 domain that is bound to the chain being verified. */
|
|
21
|
+
export function getGestureGateIntentDomain(chainId) {
|
|
22
|
+
return { name: "GestureGate", version: "1", chainId };
|
|
23
|
+
}
|
|
24
|
+
/** Testnet compatibility export. New integrations select the domain by chain. */
|
|
25
|
+
export const gestureGateIntentDomain = getGestureGateIntentDomain(monadTestnetChainId);
|
|
19
26
|
export const gestureGateIntentTypes = {
|
|
20
27
|
GateIntent: [
|
|
21
28
|
{ name: "subject", type: "address" },
|
|
@@ -57,22 +64,22 @@ function defaultDeployment() {
|
|
|
57
64
|
throw new Error("The official GestureGate Monad Testnet deployment is missing.");
|
|
58
65
|
return deployment;
|
|
59
66
|
}
|
|
60
|
-
export async function createChallengeIntent(subject, projectId, signTypedData, now = Date.now()) {
|
|
67
|
+
export async function createChallengeIntent(subject, projectId, signTypedData, now = Date.now(), chainId = monadTestnetChainId) {
|
|
61
68
|
if (!/^ggp_[A-Za-z0-9_-]{8,}$/.test(projectId))
|
|
62
69
|
throw new Error("projectId must be a valid GestureGate project ID.");
|
|
63
70
|
const expiresAt = BigInt(Math.floor(now / 1_000) + 180);
|
|
64
71
|
const nonce = randomNonce();
|
|
65
72
|
const signature = await signTypedData({
|
|
66
|
-
domain:
|
|
73
|
+
domain: getGestureGateIntentDomain(chainId),
|
|
67
74
|
types: gestureGateIntentTypes,
|
|
68
75
|
primaryType: "GateIntent",
|
|
69
76
|
message: { subject, projectId, action: "REQUEST_CHALLENGE", nonce, expiresAt },
|
|
70
77
|
});
|
|
71
|
-
return { subject, projectId, nonce, expiresAt: expiresAt.toString(), signature };
|
|
78
|
+
return { subject, projectId, nonce, expiresAt: expiresAt.toString(), signature, chainId };
|
|
72
79
|
}
|
|
73
80
|
export async function startHostedVerification(options) {
|
|
74
81
|
const deployment = options.deployment ?? defaultDeployment();
|
|
75
|
-
const intent = await createChallengeIntent(options.address, options.projectId, options.signTypedData);
|
|
82
|
+
const intent = await createChallengeIntent(options.address, options.projectId, options.signTypedData, Date.now(), deployment.chainId);
|
|
76
83
|
const response = await fetch(apiPath(deployment.apiOrigin, "/api/challenges"), {
|
|
77
84
|
method: "POST",
|
|
78
85
|
headers: { "content-type": "application/json" },
|
|
@@ -81,7 +88,7 @@ export async function startHostedVerification(options) {
|
|
|
81
88
|
const result = await response.json();
|
|
82
89
|
if (!response.ok)
|
|
83
90
|
throw new Error(result.error ?? "GestureGate could not start verification.");
|
|
84
|
-
if (!result.challengeId || !result.expiresAt || !result.transactionHash || !result.verifyUrl) {
|
|
91
|
+
if (!result.challengeId || !result.expiresAt || !result.transactionHash || !result.verifyUrl || result.chainId !== deployment.chainId) {
|
|
85
92
|
throw new Error("GestureGate returned an incomplete verification session.");
|
|
86
93
|
}
|
|
87
94
|
// The API also returns an inline-flow session token. Hosted partners never
|
|
@@ -91,6 +98,7 @@ export async function startHostedVerification(options) {
|
|
|
91
98
|
expiresAt: result.expiresAt,
|
|
92
99
|
transactionHash: result.transactionHash,
|
|
93
100
|
verifyUrl: result.verifyUrl,
|
|
101
|
+
chainId: result.chainId,
|
|
94
102
|
};
|
|
95
103
|
}
|
|
96
104
|
export async function isVerifiedWithin(options) {
|
|
@@ -179,23 +187,32 @@ export function createGestureGateClient(options) {
|
|
|
179
187
|
if (!Number.isInteger(options.defaultTtlSeconds) || options.defaultTtlSeconds <= 0) {
|
|
180
188
|
throw new Error("defaultTtlSeconds must be a positive whole number.");
|
|
181
189
|
}
|
|
182
|
-
const
|
|
190
|
+
const deploymentForCurrentChain = async () => {
|
|
191
|
+
const chainId = await options.publicClient.getChainId();
|
|
192
|
+
const deployment = options.deployments?.[chainId] ?? options.deployment ?? getGestureGateDeployment(chainId);
|
|
193
|
+
if (!deployment)
|
|
194
|
+
throw new Error("GestureGate is not configured for the connected network.");
|
|
195
|
+
if (deployment.chainId !== chainId)
|
|
196
|
+
throw new Error("Your wallet is connected to the wrong network for this GestureGate deployment.");
|
|
197
|
+
return deployment;
|
|
198
|
+
};
|
|
199
|
+
const check = async (address, ttlSeconds = options.defaultTtlSeconds) => getVerificationStatus({
|
|
183
200
|
publicClient: options.publicClient,
|
|
184
201
|
address,
|
|
185
202
|
ttlSeconds,
|
|
186
|
-
deployment:
|
|
203
|
+
deployment: await deploymentForCurrentChain(),
|
|
187
204
|
});
|
|
188
205
|
return Object.freeze({
|
|
189
206
|
check,
|
|
190
|
-
open: (input) => openHostedVerification({
|
|
207
|
+
open: async (input) => openHostedVerification({
|
|
191
208
|
projectId: options.projectId,
|
|
192
|
-
deployment:
|
|
209
|
+
deployment: await deploymentForCurrentChain(),
|
|
193
210
|
...input,
|
|
194
211
|
}),
|
|
195
|
-
ensureVerified: (input) => ensureVerified({
|
|
212
|
+
ensureVerified: async (input) => ensureVerified({
|
|
196
213
|
publicClient: options.publicClient,
|
|
197
214
|
projectId: options.projectId,
|
|
198
|
-
deployment:
|
|
215
|
+
deployment: await deploymentForCurrentChain(),
|
|
199
216
|
ttlSeconds: input.ttlSeconds ?? options.defaultTtlSeconds,
|
|
200
217
|
...input,
|
|
201
218
|
}),
|