@gesturegate/sdk 0.1.0 → 0.1.1

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  import { type Address, type Hex, type PublicClient } from "viem";
2
2
  export declare const monadTestnetChainId = 10143;
3
+ /** The official GestureGate deployment. Partners do not configure these values. */
4
+ export declare const gestureGateDeployments: {
5
+ readonly 10143: {
6
+ readonly chainId: 10143;
7
+ readonly apiOrigin: "https://gesturegate.vercel.app";
8
+ readonly registryAddress: Address;
9
+ };
10
+ };
11
+ export type GestureGateDeployment = {
12
+ chainId: number;
13
+ apiOrigin: string;
14
+ registryAddress: Address;
15
+ };
16
+ export declare function getGestureGateDeployment(chainId: number): GestureGateDeployment | undefined;
3
17
  export declare const gestureGateIntentDomain: {
4
18
  readonly name: "GestureGate";
5
19
  readonly version: "1";
@@ -9,6 +23,9 @@ export declare const gestureGateIntentTypes: {
9
23
  readonly GateIntent: readonly [{
10
24
  readonly name: "subject";
11
25
  readonly type: "address";
26
+ }, {
27
+ readonly name: "projectId";
28
+ readonly type: "string";
12
29
  }, {
13
30
  readonly name: "action";
14
31
  readonly type: "string";
@@ -41,6 +58,7 @@ export type SignTypedData = (args: {
41
58
  primaryType: "GateIntent";
42
59
  message: {
43
60
  subject: Address;
61
+ projectId: string;
44
62
  action: "REQUEST_CHALLENGE";
45
63
  nonce: Hex;
46
64
  expiresAt: bigint;
@@ -59,33 +77,36 @@ export type HostedVerifiedMessage = {
59
77
  };
60
78
  export type VerificationCheck = {
61
79
  publicClient: PublicClient;
62
- registryAddress: Address;
63
80
  address: Address;
64
81
  ttlSeconds: number;
82
+ /** For local development or a future self-hosted GestureGate deployment. */
83
+ deployment?: GestureGateDeployment;
65
84
  };
66
85
  export type VerificationStatus = Pick<VerificationCheck, "address" | "ttlSeconds"> & {
67
86
  isVerified: boolean;
68
87
  };
69
88
  export type EnsureVerifiedOptions = VerificationCheck & {
70
- apiOrigin: string;
89
+ projectId: string;
71
90
  signTypedData: SignTypedData;
72
91
  popupName?: string;
73
92
  popupFeatures?: string;
74
93
  };
75
94
  export type GestureGateClientOptions = Omit<VerificationCheck, "address" | "ttlSeconds"> & {
76
- apiOrigin: string;
95
+ projectId: string;
77
96
  defaultTtlSeconds: number;
78
97
  };
79
- export declare function createChallengeIntent(subject: Address, signTypedData: SignTypedData, now?: number): Promise<{
98
+ export declare function createChallengeIntent(subject: Address, projectId: string, signTypedData: SignTypedData, now?: number): Promise<{
80
99
  subject: `0x${string}`;
100
+ projectId: string;
81
101
  nonce: `0x${string}`;
82
102
  expiresAt: string;
83
103
  signature: `0x${string}`;
84
104
  }>;
85
105
  export declare function startHostedVerification(options: {
86
- apiOrigin: string;
106
+ projectId: string;
87
107
  address: Address;
88
108
  signTypedData: SignTypedData;
109
+ deployment?: GestureGateDeployment;
89
110
  }): Promise<{
90
111
  challengeId: string;
91
112
  expiresAt: string;
@@ -96,9 +117,10 @@ export declare function isVerifiedWithin(options: VerificationCheck): Promise<bo
96
117
  /** Returns an explicit address-bound status for application UI and guards. */
97
118
  export declare function getVerificationStatus(options: VerificationCheck): Promise<VerificationStatus>;
98
119
  export declare function openHostedVerification(options: {
99
- apiOrigin: string;
120
+ projectId: string;
100
121
  address: Address;
101
122
  signTypedData: SignTypedData;
123
+ deployment?: GestureGateDeployment;
102
124
  popupName?: string;
103
125
  popupFeatures?: string;
104
126
  }): Promise<HostedVerifiedMessage>;
@@ -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;AAEzC,eAAO,MAAM,uBAAuB;;;;CAI1B,CAAC;AAEX,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;CAOzB,CAAC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AE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAMnG;AAED,wBAAsB,sBAAsB,CAAC,OAAO,EAAE;IACpD,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,aAAa,CAAC;IAC7B,UAAU,CAAC,EAAE,qBAAqB,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,kCAsCA;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,qBAAqB;;;;;;;;GAUlE;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,wBAAwB;qBAI/C,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;;;;;;;;;GAQ9I"}
package/dist/index.js CHANGED
@@ -1,5 +1,16 @@
1
1
  import { keccak256, toHex } from "viem";
2
2
  export const monadTestnetChainId = 10143;
3
+ /** The official GestureGate deployment. Partners do not configure these values. */
4
+ export const gestureGateDeployments = {
5
+ [monadTestnetChainId]: {
6
+ chainId: monadTestnetChainId,
7
+ apiOrigin: "https://gesturegate.vercel.app",
8
+ registryAddress: "0x0B8a46b6c46a37B8B91C78D3f73549747e2027e3",
9
+ },
10
+ };
11
+ export function getGestureGateDeployment(chainId) {
12
+ return gestureGateDeployments[chainId];
13
+ }
3
14
  export const gestureGateIntentDomain = {
4
15
  name: "GestureGate",
5
16
  version: "1",
@@ -8,6 +19,7 @@ export const gestureGateIntentDomain = {
8
19
  export const gestureGateIntentTypes = {
9
20
  GateIntent: [
10
21
  { name: "subject", type: "address" },
22
+ { name: "projectId", type: "string" },
11
23
  { name: "action", type: "string" },
12
24
  { name: "nonce", type: "bytes32" },
13
25
  { name: "expiresAt", type: "uint256" },
@@ -30,20 +42,38 @@ function randomNonce() {
30
42
  function apiPath(apiOrigin, path) {
31
43
  return `${apiOrigin.replace(/\/$/, "")}${path}`;
32
44
  }
33
- export async function createChallengeIntent(subject, signTypedData, now = Date.now()) {
45
+ async function resolveDeployment(publicClient, override) {
46
+ const chainId = await publicClient.getChainId();
47
+ const deployment = override ?? getGestureGateDeployment(chainId);
48
+ if (!deployment)
49
+ throw new Error("GestureGate is not available on this network. Switch to Monad Testnet.");
50
+ if (deployment.chainId !== chainId)
51
+ throw new Error("Your wallet is connected to the wrong network for this GestureGate deployment.");
52
+ return deployment;
53
+ }
54
+ function defaultDeployment() {
55
+ const deployment = getGestureGateDeployment(monadTestnetChainId);
56
+ if (!deployment)
57
+ throw new Error("The official GestureGate Monad Testnet deployment is missing.");
58
+ return deployment;
59
+ }
60
+ export async function createChallengeIntent(subject, projectId, signTypedData, now = Date.now()) {
61
+ if (!/^ggp_[A-Za-z0-9_-]{8,}$/.test(projectId))
62
+ throw new Error("projectId must be a valid GestureGate project ID.");
34
63
  const expiresAt = BigInt(Math.floor(now / 1_000) + 180);
35
64
  const nonce = randomNonce();
36
65
  const signature = await signTypedData({
37
66
  domain: gestureGateIntentDomain,
38
67
  types: gestureGateIntentTypes,
39
68
  primaryType: "GateIntent",
40
- message: { subject, action: "REQUEST_CHALLENGE", nonce, expiresAt },
69
+ message: { subject, projectId, action: "REQUEST_CHALLENGE", nonce, expiresAt },
41
70
  });
42
- return { subject, nonce, expiresAt: expiresAt.toString(), signature };
71
+ return { subject, projectId, nonce, expiresAt: expiresAt.toString(), signature };
43
72
  }
44
73
  export async function startHostedVerification(options) {
45
- const intent = await createChallengeIntent(options.address, options.signTypedData);
46
- const response = await fetch(apiPath(options.apiOrigin, "/api/challenges"), {
74
+ const deployment = options.deployment ?? defaultDeployment();
75
+ const intent = await createChallengeIntent(options.address, options.projectId, options.signTypedData);
76
+ const response = await fetch(apiPath(deployment.apiOrigin, "/api/challenges"), {
47
77
  method: "POST",
48
78
  headers: { "content-type": "application/json" },
49
79
  body: JSON.stringify(intent),
@@ -67,8 +97,9 @@ export async function isVerifiedWithin(options) {
67
97
  if (!Number.isInteger(options.ttlSeconds) || options.ttlSeconds <= 0) {
68
98
  throw new Error("ttlSeconds must be a positive whole number.");
69
99
  }
100
+ const deployment = await resolveDeployment(options.publicClient, options.deployment);
70
101
  return options.publicClient.readContract({
71
- address: options.registryAddress,
102
+ address: deployment.registryAddress,
72
103
  abi: gestureGateRegistryAbi,
73
104
  functionName: "isVerifiedWithin",
74
105
  args: [options.address, BigInt(options.ttlSeconds)],
@@ -91,9 +122,10 @@ export async function openHostedVerification(options) {
91
122
  if (!popup)
92
123
  throw new Error("Popup was blocked. Allow popups to verify with GestureGate.");
93
124
  try {
125
+ const deployment = options.deployment ?? defaultDeployment();
94
126
  const start = await startHostedVerification(options);
95
127
  popup.location.assign(start.verifyUrl);
96
- const expectedOrigin = new URL(options.apiOrigin).origin;
128
+ const expectedOrigin = new URL(deployment.apiOrigin).origin;
97
129
  return await new Promise((resolve, reject) => {
98
130
  const closeTimer = window.setInterval(() => {
99
131
  if (popup.closed) {
@@ -149,20 +181,21 @@ export function createGestureGateClient(options) {
149
181
  }
150
182
  const check = (address, ttlSeconds = options.defaultTtlSeconds) => getVerificationStatus({
151
183
  publicClient: options.publicClient,
152
- registryAddress: options.registryAddress,
153
184
  address,
154
185
  ttlSeconds,
186
+ deployment: options.deployment,
155
187
  });
156
188
  return Object.freeze({
157
189
  check,
158
190
  open: (input) => openHostedVerification({
159
- apiOrigin: options.apiOrigin,
191
+ projectId: options.projectId,
192
+ deployment: options.deployment,
160
193
  ...input,
161
194
  }),
162
195
  ensureVerified: (input) => ensureVerified({
163
196
  publicClient: options.publicClient,
164
- registryAddress: options.registryAddress,
165
- apiOrigin: options.apiOrigin,
197
+ projectId: options.projectId,
198
+ deployment: options.deployment,
166
199
  ttlSeconds: input.ttlSeconds ?? options.defaultTtlSeconds,
167
200
  ...input,
168
201
  }),
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@gesturegate/sdk",
3
- "version": "0.1.0",
4
- "description": "Framework-neutral hosted verification client for GestureGate on Monad.",
5
- "license": "MIT",
6
- "type": "module",
7
- "sideEffects": false,
8
- "keywords": ["captcha", "human-verification", "monad", "viem", "web3"],
3
+ "version": "0.1.1",
4
+ "description": "Framework-neutral hosted verification client for GestureGate on Monad.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "keywords": ["captcha", "human-verification", "monad", "viem", "web3"],
9
9
  "files": ["dist"],
10
10
  "main": "./dist/index.js",
11
11
  "types": "./dist/index.d.ts",
@@ -15,12 +15,12 @@
15
15
  "import": "./dist/index.js"
16
16
  }
17
17
  },
18
- "scripts": {
19
- "build": "tsc -p tsconfig.json"
20
- },
21
- "publishConfig": {
22
- "access": "public"
23
- },
18
+ "scripts": {
19
+ "build": "tsc -p tsconfig.json"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
24
  "peerDependencies": {
25
25
  "viem": ">=2.0.0"
26
26
  }