@neus/sdk 1.1.0 → 1.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/README.md +206 -206
- package/cjs/client.cjs +141 -2
- package/cjs/errors.cjs +2 -35
- package/cjs/gates.cjs +1 -21
- package/cjs/index.cjs +153 -2
- package/cjs/utils.cjs +2 -0
- package/cli/neus.mjs +18 -10
- package/client.js +91 -2
- package/errors.js +154 -189
- package/gates.js +0 -20
- package/index.js +2 -0
- package/package.json +142 -143
- package/sponsor.js +95 -0
- package/types.d.ts +30 -1
- package/utils.js +2 -0
- package/widgets/README.md +1 -1
- package/widgets/verify-gate/dist/VerifyGate.js +20 -5
- package/CHANGELOG.md +0 -3
- package/neus-logo.svg +0 -3
package/README.md
CHANGED
|
@@ -1,206 +1,206 @@
|
|
|
1
|
-
# @neus/sdk
|
|
2
|
-
|
|
3
|
-
Create, check, and reuse NEUS trust receipts from apps and backends. The same package ships the **`neus`** CLI for hosted MCP setup and portable agent import.
|
|
4
|
-
|
|
5
|
-
NEUS makes trust portable across apps, agents, and ecosystems before access, payment, or action.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## Install (library)
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
npm install @neus/sdk
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Bring Your Own Agent (BYOA)
|
|
16
|
-
|
|
17
|
-
Already have an agent setup? Use the CLI to
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
npx -y -p @neus/sdk neus import
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
This
|
|
24
|
-
|
|
25
|
-
*To check what will be imported without writing changes:*
|
|
26
|
-
```bash
|
|
27
|
-
npx -y -p @neus/sdk neus import --dry-run
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## Connect editors and assistants
|
|
31
|
-
|
|
32
|
-
| Topic | Link |
|
|
33
|
-
| --------------------------------- | ----------------------------------------------------------------------------- |
|
|
34
|
-
| Setup, JSON snippets, and headers | [MCP setup](https://docs.neus.network/mcp/setup) |
|
|
35
|
-
| Tools and session order | [MCP overview](https://docs.neus.network/mcp/overview) |
|
|
36
|
-
| Discovery URLs | [Discovery and endpoints](https://docs.neus.network/mcp/endpoints) |
|
|
37
|
-
|
|
|
38
|
-
|
|
39
|
-
Prefer `neus setup` over hand-editing config files so every host stays on **`https://mcp.neus.network/mcp`**.
|
|
40
|
-
|
|
41
|
-
## What you can ship
|
|
42
|
-
|
|
43
|
-
- Hosted verification flows that return a reusable receipt
|
|
44
|
-
- Server checks before access, rewards, payments, or actions
|
|
45
|
-
- React gates with `VerifyGate`
|
|
46
|
-
- Agent identity and scoped delegation
|
|
47
|
-
- MCP setup for assistants and agent tools
|
|
48
|
-
|
|
49
|
-
## Fastest path: Hosted Verify
|
|
50
|
-
|
|
51
|
-
Use Hosted Verify when you want NEUS to handle the signing/verification flow outside your app UI.
|
|
52
|
-
|
|
53
|
-
```js
|
|
54
|
-
import { getHostedCheckoutUrl } from '@neus/sdk';
|
|
55
|
-
|
|
56
|
-
const url = getHostedCheckoutUrl({
|
|
57
|
-
verifiers: ['ownership-basic'],
|
|
58
|
-
returnUrl: 'https://yourapp.com/auth/callback'
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
window.location.assign(url);
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
After completion, NEUS redirects back with a
|
|
65
|
-
|
|
66
|
-
##
|
|
67
|
-
|
|
68
|
-
Use this when your app handles signing. This example is EVM. For non-EVM
|
|
69
|
-
|
|
70
|
-
```js
|
|
71
|
-
import { NeusClient } from '@neus/sdk';
|
|
72
|
-
|
|
73
|
-
const client = new NeusClient({
|
|
74
|
-
appId: 'your-app-id'
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
const proof = await client.verify({
|
|
78
|
-
verifier: 'ownership-basic',
|
|
79
|
-
data: {
|
|
80
|
-
owner: '0x...',
|
|
81
|
-
contentType: 'application/json',
|
|
82
|
-
content: JSON.stringify({
|
|
83
|
-
title: 'Verified claim',
|
|
84
|
-
type: 'project-update',
|
|
85
|
-
summary: 'Public summary of what is being proven.'
|
|
86
|
-
}),
|
|
87
|
-
reference: {
|
|
88
|
-
type: 'url',
|
|
89
|
-
id: 'https://example.com/source',
|
|
90
|
-
title: 'Source record'
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
wallet: window.ethereum // EVM provider
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
console.log(proof.qHash);
|
|
97
|
-
console.log(proof.proofUrl);
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
## React widget
|
|
101
|
-
|
|
102
|
-
Use `VerifyGate` when you want a drop-in verification flow in React.
|
|
103
|
-
|
|
104
|
-
```jsx
|
|
105
|
-
import { VerifyGate } from '@neus/sdk/widgets';
|
|
106
|
-
|
|
107
|
-
export function Page() {
|
|
108
|
-
return (
|
|
109
|
-
<VerifyGate
|
|
110
|
-
appId="your-app-id"
|
|
111
|
-
requiredVerifiers={['ownership-basic']}
|
|
112
|
-
verifierData={{
|
|
113
|
-
'ownership-basic': {
|
|
114
|
-
owner: '0x...',
|
|
115
|
-
contentType: 'application/json',
|
|
116
|
-
content: JSON.stringify({
|
|
117
|
-
title: 'Verified claim',
|
|
118
|
-
summary: 'Public summary of what is being proven.'
|
|
119
|
-
}),
|
|
120
|
-
reference: {
|
|
121
|
-
type: 'url',
|
|
122
|
-
id: 'https://example.com/source'
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}}
|
|
126
|
-
onVerified={result => {
|
|
127
|
-
console.log(result.qHash || result.qHashes);
|
|
128
|
-
}}
|
|
129
|
-
/>
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
## Check receipts
|
|
135
|
-
|
|
136
|
-
Use `gateCheck` from trusted server code when you need allow/deny or eligibility checks.
|
|
137
|
-
|
|
138
|
-
```js
|
|
139
|
-
import { NeusClient } from '@neus/sdk';
|
|
140
|
-
|
|
141
|
-
const client = new NeusClient({
|
|
142
|
-
appId: 'your-app-id'
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
const result = await client.gateCheck({
|
|
146
|
-
address: '0x...',
|
|
147
|
-
verifierIds: ['ownership-basic']
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
if (!result.data?.eligible) {
|
|
151
|
-
throw new Error('Access denied');
|
|
152
|
-
}
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
Never ship access keys in browser code.
|
|
156
|
-
|
|
157
|
-
## Core methods
|
|
158
|
-
|
|
159
|
-
| Method | Use it for |
|
|
160
|
-
| ------------------------------- | ------------------------------------------- |
|
|
161
|
-
| `getHostedCheckoutUrl()` | Send a user to Hosted Verify |
|
|
162
|
-
| `client.verify()` | Create a proof |
|
|
163
|
-
| `client.getProof()` | Fetch a receipt by `qHash` |
|
|
164
|
-
| `client.pollProofStatus()` | Wait for async completion |
|
|
165
|
-
| `client.gateCheck()` | Server-side eligibility checks |
|
|
166
|
-
| `client.checkGate()` | Local preview against already-loaded proofs |
|
|
167
|
-
| `client.createWalletLinkData()` | Wallet-link payloads |
|
|
168
|
-
|
|
169
|
-
## Configuration
|
|
170
|
-
|
|
171
|
-
```js
|
|
172
|
-
const client = new NeusClient({
|
|
173
|
-
apiUrl: 'https://api.neus.network',
|
|
174
|
-
appId: 'your-app-id',
|
|
175
|
-
timeout: 30000
|
|
176
|
-
});
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
`appId` is public attribution for your app.
|
|
180
|
-
`apiKey` / `npk_*` is optional and server-side only.
|
|
181
|
-
|
|
182
|
-
## MCP step-by-step
|
|
183
|
-
|
|
184
|
-
```bash
|
|
185
|
-
npx -y -p @neus/sdk neus setup
|
|
186
|
-
npx -y -p @neus/sdk neus auth
|
|
187
|
-
npx -y -p @neus/sdk neus doctor --live
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
Re-sign in or rotate credentials:
|
|
191
|
-
|
|
192
|
-
```bash
|
|
193
|
-
npx -y -p @neus/sdk neus auth
|
|
194
|
-
npx -y -p @neus/sdk neus auth --access-key <npk_...> # servers and CI only
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
## Docs
|
|
200
|
-
|
|
201
|
-
- Quickstart: https://docs.neus.network/quickstart
|
|
202
|
-
- JavaScript SDK: https://docs.neus.network/sdks/javascript
|
|
203
|
-
- Ownership Basic: https://docs.neus.network/verification/ownership-basic
|
|
204
|
-
- Widgets: https://docs.neus.network/widgets/overview
|
|
205
|
-
- MCP: https://docs.neus.network/mcp/overview
|
|
206
|
-
- API: https://docs.neus.network/api/overview
|
|
1
|
+
# @neus/sdk
|
|
2
|
+
|
|
3
|
+
Create, check, and reuse NEUS trust receipts from apps and backends. The same package ships the **`neus`** CLI for hosted MCP setup and portable agent import.
|
|
4
|
+
|
|
5
|
+
NEUS makes trust portable across apps, agents, and ecosystems before access, payment, or action.
|
|
6
|
+
|
|
7
|
+
Roadmap: [docs.neus.network/platform/status](https://docs.neus.network/platform/status)
|
|
8
|
+
|
|
9
|
+
## Install (library)
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @neus/sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Bring Your Own Agent (BYOA)
|
|
16
|
+
|
|
17
|
+
Already have an agent setup? Use the CLI to package supported local agent context, including instructions, rules, skills, and MCP server references from **OpenClaw, Cursor, Claude Code, and Claude Desktop**:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx -y -p @neus/sdk neus import
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
This prepares a local portable-agent manifest. In MCP, call `neus_agent_link` first; if setup is missing, use `neus_agent_create`, complete the hosted or signing steps, then call `neus_agent_link` again until `linked: true`.
|
|
24
|
+
|
|
25
|
+
*To check what will be imported without writing changes:*
|
|
26
|
+
```bash
|
|
27
|
+
npx -y -p @neus/sdk neus import --dry-run
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Connect editors and assistants
|
|
31
|
+
|
|
32
|
+
| Topic | Link |
|
|
33
|
+
| --------------------------------- | ----------------------------------------------------------------------------- |
|
|
34
|
+
| Setup, JSON snippets, and headers | [MCP setup](https://docs.neus.network/mcp/setup) |
|
|
35
|
+
| Tools and session order | [MCP overview](https://docs.neus.network/mcp/overview) |
|
|
36
|
+
| Discovery URLs | [Discovery and endpoints](https://docs.neus.network/mcp/endpoints) |
|
|
37
|
+
| NEUS for AI assistants | [NEUS for AI assistants](https://docs.neus.network/mcp/ide-plugin) |
|
|
38
|
+
|
|
39
|
+
Prefer `neus setup` over hand-editing config files so every host stays on **`https://mcp.neus.network/mcp`**.
|
|
40
|
+
|
|
41
|
+
## What you can ship
|
|
42
|
+
|
|
43
|
+
- Hosted verification flows that return a reusable receipt
|
|
44
|
+
- Server checks before access, rewards, payments, or actions
|
|
45
|
+
- React gates with `VerifyGate`
|
|
46
|
+
- Agent identity and scoped delegation
|
|
47
|
+
- MCP setup for assistants and agent tools
|
|
48
|
+
|
|
49
|
+
## Fastest path: Hosted Verify
|
|
50
|
+
|
|
51
|
+
Use Hosted Verify when you want NEUS to handle the signing/verification flow outside your app UI.
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
import { getHostedCheckoutUrl } from '@neus/sdk';
|
|
55
|
+
|
|
56
|
+
const url = getHostedCheckoutUrl({
|
|
57
|
+
verifiers: ['ownership-basic'],
|
|
58
|
+
returnUrl: 'https://yourapp.com/auth/callback'
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
window.location.assign(url);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
After completion, NEUS redirects back with a `qHash`. Store it with your user or record.
|
|
65
|
+
|
|
66
|
+
## Advanced: in-app signing
|
|
67
|
+
|
|
68
|
+
Use this only when your app intentionally handles signing. This example is EVM. For non-EVM accounts, pass the provider explicitly and include `chain` as a CAIP-2 value.
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
import { NeusClient } from '@neus/sdk';
|
|
72
|
+
|
|
73
|
+
const client = new NeusClient({
|
|
74
|
+
appId: 'your-app-id'
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const proof = await client.verify({
|
|
78
|
+
verifier: 'ownership-basic',
|
|
79
|
+
data: {
|
|
80
|
+
owner: '0x...',
|
|
81
|
+
contentType: 'application/json',
|
|
82
|
+
content: JSON.stringify({
|
|
83
|
+
title: 'Verified claim',
|
|
84
|
+
type: 'project-update',
|
|
85
|
+
summary: 'Public summary of what is being proven.'
|
|
86
|
+
}),
|
|
87
|
+
reference: {
|
|
88
|
+
type: 'url',
|
|
89
|
+
id: 'https://example.com/source',
|
|
90
|
+
title: 'Source record'
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
wallet: window.ethereum // EVM provider
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
console.log(proof.qHash);
|
|
97
|
+
console.log(proof.proofUrl);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## React widget
|
|
101
|
+
|
|
102
|
+
Use `VerifyGate` when you want a drop-in verification flow in React.
|
|
103
|
+
|
|
104
|
+
```jsx
|
|
105
|
+
import { VerifyGate } from '@neus/sdk/widgets';
|
|
106
|
+
|
|
107
|
+
export function Page() {
|
|
108
|
+
return (
|
|
109
|
+
<VerifyGate
|
|
110
|
+
appId="your-app-id"
|
|
111
|
+
requiredVerifiers={['ownership-basic']}
|
|
112
|
+
verifierData={{
|
|
113
|
+
'ownership-basic': {
|
|
114
|
+
owner: '0x...',
|
|
115
|
+
contentType: 'application/json',
|
|
116
|
+
content: JSON.stringify({
|
|
117
|
+
title: 'Verified claim',
|
|
118
|
+
summary: 'Public summary of what is being proven.'
|
|
119
|
+
}),
|
|
120
|
+
reference: {
|
|
121
|
+
type: 'url',
|
|
122
|
+
id: 'https://example.com/source'
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}}
|
|
126
|
+
onVerified={result => {
|
|
127
|
+
console.log(result.qHash || result.qHashes);
|
|
128
|
+
}}
|
|
129
|
+
/>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Check receipts
|
|
135
|
+
|
|
136
|
+
Use `gateCheck` from trusted server code when you need allow/deny or eligibility checks.
|
|
137
|
+
|
|
138
|
+
```js
|
|
139
|
+
import { NeusClient } from '@neus/sdk';
|
|
140
|
+
|
|
141
|
+
const client = new NeusClient({
|
|
142
|
+
appId: 'your-app-id'
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const result = await client.gateCheck({
|
|
146
|
+
address: '0x...',
|
|
147
|
+
verifierIds: ['ownership-basic']
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
if (!result.data?.eligible) {
|
|
151
|
+
throw new Error('Access denied');
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Never ship access keys in browser code.
|
|
156
|
+
|
|
157
|
+
## Core methods
|
|
158
|
+
|
|
159
|
+
| Method | Use it for |
|
|
160
|
+
| ------------------------------- | ------------------------------------------- |
|
|
161
|
+
| `getHostedCheckoutUrl()` | Send a user to Hosted Verify |
|
|
162
|
+
| `client.verify()` | Create a proof |
|
|
163
|
+
| `client.getProof()` | Fetch a receipt by `qHash` |
|
|
164
|
+
| `client.pollProofStatus()` | Wait for async completion |
|
|
165
|
+
| `client.gateCheck()` | Server-side eligibility checks |
|
|
166
|
+
| `client.checkGate()` | Local preview against already-loaded proofs |
|
|
167
|
+
| `client.createWalletLinkData()` | Wallet-link payloads |
|
|
168
|
+
|
|
169
|
+
## Configuration
|
|
170
|
+
|
|
171
|
+
```js
|
|
172
|
+
const client = new NeusClient({
|
|
173
|
+
apiUrl: 'https://api.neus.network',
|
|
174
|
+
appId: 'your-app-id',
|
|
175
|
+
timeout: 30000
|
|
176
|
+
});
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
`appId` is public attribution for your app.
|
|
180
|
+
`apiKey` / `npk_*` is optional and server-side only.
|
|
181
|
+
|
|
182
|
+
## MCP step-by-step
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
npx -y -p @neus/sdk neus setup
|
|
186
|
+
npx -y -p @neus/sdk neus auth
|
|
187
|
+
npx -y -p @neus/sdk neus doctor --live
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Re-sign in or rotate credentials:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
npx -y -p @neus/sdk neus auth
|
|
194
|
+
npx -y -p @neus/sdk neus auth --access-key <npk_...> # servers and CI only
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Editors with plugin marketplaces can install **`neus-trust@neus`** for the bundled session workflow. OpenClaw, Hermes, and other runtimes: see [NEUS for AI assistants](https://docs.neus.network/mcp/ide-plugin) for exact paths.
|
|
198
|
+
|
|
199
|
+
## Docs
|
|
200
|
+
|
|
201
|
+
- Quickstart: https://docs.neus.network/quickstart
|
|
202
|
+
- JavaScript SDK: https://docs.neus.network/sdks/javascript
|
|
203
|
+
- Ownership Basic: https://docs.neus.network/verification/ownership-basic
|
|
204
|
+
- Widgets: https://docs.neus.network/widgets/overview
|
|
205
|
+
- MCP: https://docs.neus.network/mcp/overview
|
|
206
|
+
- API: https://docs.neus.network/api/overview
|
package/cjs/client.cjs
CHANGED
|
@@ -129,6 +129,83 @@ var ConfigurationError = class extends SDKError {
|
|
|
129
129
|
}
|
|
130
130
|
};
|
|
131
131
|
|
|
132
|
+
// sponsor.js
|
|
133
|
+
async function fetchSponsorGrant(params = {}) {
|
|
134
|
+
const {
|
|
135
|
+
apiUrl = "https://api.neus.network",
|
|
136
|
+
appId,
|
|
137
|
+
orgWallet,
|
|
138
|
+
verifierIds = [],
|
|
139
|
+
targetChains = [],
|
|
140
|
+
origin,
|
|
141
|
+
expiresInSeconds = 900,
|
|
142
|
+
fetchImpl = fetch
|
|
143
|
+
} = params;
|
|
144
|
+
const normalizedAppId = typeof appId === "string" ? appId.trim() : "";
|
|
145
|
+
const normalizedOrg = typeof orgWallet === "string" ? orgWallet.trim().toLowerCase() : "";
|
|
146
|
+
if (!normalizedAppId) {
|
|
147
|
+
throw new ValidationError("appId is required for sponsor grant");
|
|
148
|
+
}
|
|
149
|
+
if (!normalizedOrg || !/^0x[a-f0-9]{40}$/.test(normalizedOrg)) {
|
|
150
|
+
throw new ValidationError("orgWallet must be a valid EVM address");
|
|
151
|
+
}
|
|
152
|
+
let base = String(apiUrl || "https://api.neus.network").replace(/\/+$/, "");
|
|
153
|
+
try {
|
|
154
|
+
const url = new URL(base);
|
|
155
|
+
if (url.hostname.endsWith("neus.network") && url.protocol === "http:") {
|
|
156
|
+
url.protocol = "https:";
|
|
157
|
+
}
|
|
158
|
+
base = url.toString().replace(/\/+$/, "");
|
|
159
|
+
} catch {
|
|
160
|
+
}
|
|
161
|
+
const headers = {
|
|
162
|
+
"Content-Type": "application/json",
|
|
163
|
+
Accept: "application/json",
|
|
164
|
+
"X-Neus-App": normalizedAppId,
|
|
165
|
+
"X-Neus-Sdk": "js"
|
|
166
|
+
};
|
|
167
|
+
if (typeof origin === "string" && origin.trim()) {
|
|
168
|
+
headers.Origin = origin.trim();
|
|
169
|
+
}
|
|
170
|
+
const body = {
|
|
171
|
+
orgWallet: normalizedOrg,
|
|
172
|
+
scope: "sponsored-verification",
|
|
173
|
+
expiresInSeconds,
|
|
174
|
+
...Array.isArray(verifierIds) && verifierIds.length > 0 ? { verifierIds: verifierIds.map((v) => String(v).trim()).filter(Boolean).slice(0, 25) } : {},
|
|
175
|
+
...Array.isArray(targetChains) && targetChains.length > 0 ? { targetChains: targetChains.filter((n) => Number.isFinite(Number(n))).slice(0, 25) } : {}
|
|
176
|
+
};
|
|
177
|
+
let response;
|
|
178
|
+
try {
|
|
179
|
+
response = await fetchImpl(`${base}/api/v1/sponsor/grant`, {
|
|
180
|
+
method: "POST",
|
|
181
|
+
headers,
|
|
182
|
+
body: JSON.stringify(body)
|
|
183
|
+
});
|
|
184
|
+
} catch (error) {
|
|
185
|
+
throw new NetworkError(`Sponsor grant request failed: ${error?.message || String(error)}`);
|
|
186
|
+
}
|
|
187
|
+
let payload;
|
|
188
|
+
try {
|
|
189
|
+
payload = await response.json();
|
|
190
|
+
} catch {
|
|
191
|
+
payload = { success: false, error: { message: "Invalid JSON response" } };
|
|
192
|
+
}
|
|
193
|
+
if (!response.ok || payload?.success !== true) {
|
|
194
|
+
throw ApiError.fromResponse(response, payload);
|
|
195
|
+
}
|
|
196
|
+
const token = payload?.data?.sponsorGrant;
|
|
197
|
+
if (!token || typeof token !== "string") {
|
|
198
|
+
throw new ApiError("Sponsor grant response missing sponsorGrant token", payload?.error);
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
sponsorGrant: token,
|
|
202
|
+
exp: payload?.data?.exp,
|
|
203
|
+
orgWallet: payload?.data?.orgWallet || normalizedOrg,
|
|
204
|
+
appId: payload?.data?.appId || normalizedAppId,
|
|
205
|
+
maxCredits: payload?.data?.maxCredits
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
132
209
|
// utils.js
|
|
133
210
|
var PORTABLE_PROOF_SIGNER_HEADER = "Portable Proof Verification Request";
|
|
134
211
|
var BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
@@ -746,6 +823,54 @@ var NeusClient = class {
|
|
|
746
823
|
}
|
|
747
824
|
} catch {
|
|
748
825
|
}
|
|
826
|
+
this._sponsorGrantCache = null;
|
|
827
|
+
}
|
|
828
|
+
_getBillingWallet() {
|
|
829
|
+
const raw = this.config.billingWallet || this.config.sponsorOrgWallet || this.config.orgWallet || null;
|
|
830
|
+
if (typeof raw !== "string") return null;
|
|
831
|
+
const trimmed = raw.trim().toLowerCase();
|
|
832
|
+
return /^0x[a-f0-9]{40}$/.test(trimmed) ? trimmed : null;
|
|
833
|
+
}
|
|
834
|
+
_resolveIntegratorOrigin() {
|
|
835
|
+
if (typeof this.config.appOrigin === "string" && this.config.appOrigin.trim()) {
|
|
836
|
+
return this.config.appOrigin.trim();
|
|
837
|
+
}
|
|
838
|
+
try {
|
|
839
|
+
if (typeof window !== "undefined" && window.location?.origin) {
|
|
840
|
+
return window.location.origin;
|
|
841
|
+
}
|
|
842
|
+
} catch {
|
|
843
|
+
}
|
|
844
|
+
return null;
|
|
845
|
+
}
|
|
846
|
+
async _resolveSponsorGrantHeaders(verifierIds = []) {
|
|
847
|
+
const appId = typeof this.config.appId === "string" ? this.config.appId.trim() : "";
|
|
848
|
+
const orgWallet = this._getBillingWallet();
|
|
849
|
+
if (!appId || !orgWallet) {
|
|
850
|
+
return {};
|
|
851
|
+
}
|
|
852
|
+
const normalizedVerifierIds = Array.isArray(verifierIds) ? verifierIds.map((v) => String(v || "").trim()).filter(Boolean).slice(0, 25) : [];
|
|
853
|
+
const cacheKey = `${appId}:${orgWallet}:${normalizedVerifierIds.join(",")}`;
|
|
854
|
+
const now = Date.now();
|
|
855
|
+
if (this._sponsorGrantCache && this._sponsorGrantCache.key === cacheKey && this._sponsorGrantCache.expMs > now + 3e4) {
|
|
856
|
+
return { "X-Sponsor-Grant": this._sponsorGrantCache.token };
|
|
857
|
+
}
|
|
858
|
+
const origin = this._resolveIntegratorOrigin();
|
|
859
|
+
const grant = await fetchSponsorGrant({
|
|
860
|
+
apiUrl: this.baseUrl,
|
|
861
|
+
appId,
|
|
862
|
+
orgWallet,
|
|
863
|
+
verifierIds: normalizedVerifierIds,
|
|
864
|
+
origin
|
|
865
|
+
});
|
|
866
|
+
const expSeconds = Number(grant?.exp);
|
|
867
|
+
const expMs = Number.isFinite(expSeconds) && expSeconds > 0 ? expSeconds * 1e3 : now + 15 * 60 * 1e3;
|
|
868
|
+
this._sponsorGrantCache = {
|
|
869
|
+
key: cacheKey,
|
|
870
|
+
token: grant.sponsorGrant,
|
|
871
|
+
expMs
|
|
872
|
+
};
|
|
873
|
+
return { "X-Sponsor-Grant": grant.sponsorGrant };
|
|
749
874
|
}
|
|
750
875
|
_getHubChainId() {
|
|
751
876
|
const configured = Number(this.config?.hubChainId);
|
|
@@ -1418,7 +1543,8 @@ ${bytes.length}`;
|
|
|
1418
1543
|
...delegationQHash && { delegationQHash },
|
|
1419
1544
|
options: optionsPayload
|
|
1420
1545
|
};
|
|
1421
|
-
const
|
|
1546
|
+
const sponsorHeaders = await this._resolveSponsorGrantHeaders(normalizedVerifierIds);
|
|
1547
|
+
const response = await this._makeRequest("POST", "/api/v1/verification", requestData, sponsorHeaders);
|
|
1422
1548
|
if (!response.success) {
|
|
1423
1549
|
throw new ApiError(`Verification failed: ${response.error?.message || "Unknown error"}`, response.error);
|
|
1424
1550
|
}
|
|
@@ -1811,7 +1937,20 @@ ${bytes.length}`;
|
|
|
1811
1937
|
};
|
|
1812
1938
|
}
|
|
1813
1939
|
}
|
|
1814
|
-
|
|
1940
|
+
let mergedHeaders = headersOverride;
|
|
1941
|
+
if (!mergedHeaders) {
|
|
1942
|
+
try {
|
|
1943
|
+
const sponsorHeaders = await this._resolveSponsorGrantHeaders(
|
|
1944
|
+
Array.isArray(params.verifierIds) ? params.verifierIds : params.verifierIds ? [params.verifierIds] : []
|
|
1945
|
+
);
|
|
1946
|
+
if (sponsorHeaders && Object.keys(sponsorHeaders).length > 0) {
|
|
1947
|
+
mergedHeaders = sponsorHeaders;
|
|
1948
|
+
}
|
|
1949
|
+
} catch (error) {
|
|
1950
|
+
this._log("Sponsor grant unavailable for gateCheck (continuing without)", error?.message || String(error));
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
const response = await this._makeRequest("GET", `/api/v1/proofs/check?${qs.toString()}`, null, mergedHeaders);
|
|
1815
1954
|
if (!response.success) {
|
|
1816
1955
|
throw new ApiError(`Gate check failed: ${response.error?.message || "Unknown error"}`, response.error);
|
|
1817
1956
|
}
|
package/cjs/errors.cjs
CHANGED
|
@@ -26,9 +26,7 @@ __export(errors_exports, {
|
|
|
26
26
|
NetworkError: () => NetworkError,
|
|
27
27
|
SDKError: () => SDKError,
|
|
28
28
|
ValidationError: () => ValidationError,
|
|
29
|
-
VerificationError: () => VerificationError
|
|
30
|
-
createErrorFromGeneric: () => createErrorFromGeneric,
|
|
31
|
-
default: () => errors_default
|
|
29
|
+
VerificationError: () => VerificationError
|
|
32
30
|
});
|
|
33
31
|
module.exports = __toCommonJS(errors_exports);
|
|
34
32
|
var SDKError = class _SDKError extends Error {
|
|
@@ -160,36 +158,6 @@ var AuthenticationError = class extends SDKError {
|
|
|
160
158
|
};
|
|
161
159
|
}
|
|
162
160
|
};
|
|
163
|
-
function createErrorFromGeneric(error, context = {}) {
|
|
164
|
-
if (error instanceof SDKError) {
|
|
165
|
-
return error;
|
|
166
|
-
}
|
|
167
|
-
if (NetworkError.isNetworkError(error)) {
|
|
168
|
-
return new NetworkError(
|
|
169
|
-
error.message || "Network error occurred",
|
|
170
|
-
error.code || "NETWORK_ERROR",
|
|
171
|
-
error
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
if (error.name === "AbortError" || error.message.includes("timeout")) {
|
|
175
|
-
return new NetworkError("Request timeout", "TIMEOUT", error);
|
|
176
|
-
}
|
|
177
|
-
return new SDKError(
|
|
178
|
-
error.message || "Unknown error occurred",
|
|
179
|
-
error.code || "UNKNOWN_ERROR",
|
|
180
|
-
{ originalError: error, context }
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
var errors_default = {
|
|
184
|
-
SDKError,
|
|
185
|
-
ApiError,
|
|
186
|
-
ValidationError,
|
|
187
|
-
NetworkError,
|
|
188
|
-
ConfigurationError,
|
|
189
|
-
VerificationError,
|
|
190
|
-
AuthenticationError,
|
|
191
|
-
createErrorFromGeneric
|
|
192
|
-
};
|
|
193
161
|
// Annotate the CommonJS export names for ESM import in node:
|
|
194
162
|
0 && (module.exports = {
|
|
195
163
|
ApiError,
|
|
@@ -198,6 +166,5 @@ var errors_default = {
|
|
|
198
166
|
NetworkError,
|
|
199
167
|
SDKError,
|
|
200
168
|
ValidationError,
|
|
201
|
-
VerificationError
|
|
202
|
-
createErrorFromGeneric
|
|
169
|
+
VerificationError
|
|
203
170
|
});
|
package/cjs/gates.cjs
CHANGED
|
@@ -36,8 +36,7 @@ __export(gates_exports, {
|
|
|
36
36
|
WEEK: () => WEEK,
|
|
37
37
|
YEAR: () => YEAR,
|
|
38
38
|
combineGates: () => combineGates,
|
|
39
|
-
createGate: () => createGate
|
|
40
|
-
default: () => gates_default
|
|
39
|
+
createGate: () => createGate
|
|
41
40
|
});
|
|
42
41
|
module.exports = __toCommonJS(gates_exports);
|
|
43
42
|
var HOUR = 60 * 60 * 1e3;
|
|
@@ -77,25 +76,6 @@ function combineGates(...gates) {
|
|
|
77
76
|
}
|
|
78
77
|
return combined;
|
|
79
78
|
}
|
|
80
|
-
var gates_default = {
|
|
81
|
-
HOUR,
|
|
82
|
-
DAY,
|
|
83
|
-
WEEK,
|
|
84
|
-
MONTH,
|
|
85
|
-
YEAR,
|
|
86
|
-
GATE_NFT_HOLDER,
|
|
87
|
-
GATE_TOKEN_HOLDER,
|
|
88
|
-
GATE_CONTRACT_ADMIN,
|
|
89
|
-
GATE_DOMAIN_OWNER,
|
|
90
|
-
GATE_LINKED_WALLETS,
|
|
91
|
-
GATE_AGENT_IDENTITY,
|
|
92
|
-
GATE_AGENT_DELEGATION,
|
|
93
|
-
GATE_CONTENT_MODERATION,
|
|
94
|
-
GATE_WALLET_RISK,
|
|
95
|
-
GATE_PSEUDONYM,
|
|
96
|
-
createGate,
|
|
97
|
-
combineGates
|
|
98
|
-
};
|
|
99
79
|
// Annotate the CommonJS export names for ESM import in node:
|
|
100
80
|
0 && (module.exports = {
|
|
101
81
|
DAY,
|