neozip-blockchain 0.7.2 → 1.0.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/README.md CHANGED
@@ -2,12 +2,9 @@
2
2
 
3
3
  Blockchain functionality for NeoZip: **NeoZip Token Service timestamping** (stamp, upgrade, mint, verify), NFT minting, verification, and wallet management. Part of the [neozipkit monorepo](../../README.md).
4
4
 
5
- > **⚠️ Beta Version Warning**: This package is currently in **beta** status. This means:
6
- > - The API may change before the stable 1.0 release
7
- > - Some features may still be evolving
8
- > - Use in production with caution and thorough testing
9
- >
10
- > We welcome feedback on [GitHub](https://github.com/NeoWareInc/neozipkit/issues). This package is part of the [neozipkit monorepo](../../README.md).
5
+ > **Stable 1.0:** This package **1.0.2** is the first non-beta release. Please report issues on [GitHub](https://github.com/NeoWareInc/neozipkit/issues). This package is part of the [neozipkit monorepo](../../README.md).
6
+
7
+ See [WHATS_NEW.md](WHATS_NEW.md) for release notes.
11
8
 
12
9
  This package provides the client-side API and utilities that work with the sibling **[neozipkit](../neozipkit/)** package for full NZIP (NeoZip) workflows. The **NeoZip Token Service** is a **separate application**; this library contains the **NeoZip Token Service API client and helpers** used to communicate with that server (submit digests, poll for confirmations, fetch proofs, etc.). Run the NeoZip Token Service separately when using timestamping features.
13
10
 
@@ -25,7 +22,7 @@ This package provides the client-side API and utilities that work with the sibli
25
22
  ```bash
26
23
  npm install neozip-blockchain
27
24
  # or
28
- yarn add neozip-blockchain
25
+ pnpm add neozip-blockchain
29
26
  ```
30
27
 
31
28
  For full NZIP creation and verification you typically use **neozipkit** together with this package:
@@ -183,26 +180,26 @@ MIT License - see [LICENSE](LICENSE) for details.
183
180
 
184
181
  ## Publishing (npm)
185
182
 
186
- The npm tarball is intentionally minimal: compiled **`dist/`**, the **package root [`README.md`](README.md)**, and **[`LICENSE`](LICENSE)** only (`package.json` `"files"`). **`examples/`**, **`contracts/`**, and other repo docs are **not** on npm; use this repository for those.
183
+ The npm tarball is intentionally minimal: compiled **`dist/`**, the **package root [`README.md`](README.md)**, **[`WHATS_NEW.md`](WHATS_NEW.md)**, and **[`LICENSE`](LICENSE)** (`package.json` `"files"`). **`examples/`**, **`contracts/`**, and other repo docs are **not** on npm; use this repository for those.
187
184
 
188
- Preview what will ship: run **`yarn publish:dry-run`** (it uses **`npm publish --dry-run`**, which matches npm’s file list). Avoid **`yarn npm publish --dry-run`** for previews—Yarn can print extra paths such as nested `README.md` files that are **not** in the published package.
185
+ Preview what will ship: run **`pnpm publish:dry-run`** (it uses **`npm publish --dry-run`**, which matches npm’s file list).
189
186
 
190
187
  ## Development
191
188
 
192
189
  This package is part of the [neozipkit monorepo](../../README.md). From the **repository root**:
193
190
 
194
191
  ```bash
195
- yarn install
196
- yarn build # builds neozipkit first, then neozip-blockchain
197
- yarn test:unit
192
+ pnpm install
193
+ pnpm build # builds neozipkit first, then neozip-blockchain
194
+ pnpm test:unit
198
195
  ```
199
196
 
200
197
  To work on this package alone:
201
198
 
202
199
  ```bash
203
200
  cd packages/neozip-blockchain
204
- yarn build
205
- yarn test
201
+ pnpm build
202
+ pnpm test
206
203
  ```
207
204
 
208
205
  See the [monorepo README](../../README.md) for version management and release workflow.
package/WHATS_NEW.md ADDED
@@ -0,0 +1,68 @@
1
+ # What’s New in neozip-blockchain
2
+
3
+ Release notes for people who install and use **`neozip-blockchain`** from npm (alongside [`neozipkit`](https://www.npmjs.com/package/neozipkit)).
4
+
5
+ ## 1.0.2 (2026-07-28)
6
+
7
+ ### First stable release
8
+
9
+ **1.0.2** is the first non-beta release. From here on, this package follows [Semantic Versioning](https://semver.org/).
10
+
11
+ Install with a matching NeoZipKit:
12
+
13
+ ```bash
14
+ npm install neozipkit@^1.0.2 neozip-blockchain@^1.0.2
15
+ ```
16
+
17
+ ---
18
+
19
+ ## 0.8.0 (2026-06-30)
20
+
21
+ ### Token Service helpers (account, funding, identity)
22
+
23
+ New modules under the `neozip-blockchain/token-service` export for talking to a NeoZip Token Service:
24
+
25
+ - **Account / auth** — register and verify email (`browser` or `app` delivery), magic-link exchange, wallet login challenge/response, phone OTP.
26
+ - **Funding** — read funding policy/status and request a native-gas grant for the primary Data Wallet.
27
+ - **Identity** — wallet ensure/attach challenges and encrypted identity-key registration helpers.
28
+ - **HTTP utilities** — URL normalization, JSON parsing, auth error messages, access-token expiry parsing.
29
+
30
+ These APIs are **stateless**: your app stores tokens and decides how to recover from 401/403.
31
+
32
+ ### Email verification delivery
33
+
34
+ When registering, choose how the verification email is sent:
35
+
36
+ - `browser` (default) — web confirm link + code (good for scripts and CLI).
37
+ - `app` — app-style deep link.
38
+
39
+ Set `TOKEN_SERVICE_VERIFICATION_DELIVERY`, or pass `verificationDelivery` / `--browser` / `--app` in the verify-email example.
40
+
41
+ ### Breaking changes (Token Service client)
42
+
43
+ - Import from **`neozip-blockchain/token-service`** (`TokenServiceClient`, `getTokenServiceUrl`, `DEFAULT_TOKEN_SERVICE_URL`, …).
44
+ - Configure with **`TOKEN_SERVICE_URL`**, **`TOKEN_SERVICE_EMAIL`**, **`TOKEN_SERVICE_CHAIN_ID`**, optional **`TOKEN_SERVICE_VERIFICATION_DELIVERY`**, **`TOKEN_SERVICE_DEBUG`**.
45
+ - Default server: `https://testnet.token-service.neozip.io`.
46
+ - Example script renames: `example:token-service`, `example:token` (output `token.nzip`).
47
+
48
+ You must also install **`neozipkit`** yourself (peer dependency). It is not bundled inside this package.
49
+
50
+ ---
51
+
52
+ ## 0.6.0 (2026-03-03)
53
+
54
+ - **NZIP contract v2.51** on Base Sepolia (digest-only identity): `0xe4ee4f36CBAF2Bf2959740F6A0B326Acd175Ce77`
55
+ - Verify flows show the contract version (e.g. v2.51)
56
+ - Token example can reuse an existing token or mint a new one
57
+
58
+ *(0.6.0-beta.1 was the same content as a beta npm tag.)*
59
+
60
+ ---
61
+
62
+ ## 0.5.0 — Initial open-source release
63
+
64
+ - Companion to NeoZipKit for timestamping, NFT minting, and verification
65
+ - NeoZip Token Service client for stamp → upgrade → mint workflows
66
+ - NZIP contracts (v2.50 default; also v2.11 / v2.10)
67
+ - Wallet helpers (browser and Node), ZipkitMinter, ZipkitVerifier
68
+ - OpenTimestamps (OTS) support for Bitcoin-backed timestamps
package/dist/index.d.ts CHANGED
@@ -11,5 +11,5 @@ export type { EnhancedVerificationResult, BatchVerificationResult, VerificationJ
11
11
  export { Logger, configureLoggerFromEnvironment } from './utils/Logger';
12
12
  export type { LogLevel, LoggerConfig } from './utils/Logger';
13
13
  export * from './token-service';
14
- export declare const VERSION = "0.7.0";
14
+ export declare const VERSION = "1.0.2";
15
15
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -36,5 +36,5 @@ Object.defineProperty(exports, "configureLoggerFromEnvironment", { enumerable: t
36
36
  // Export NeoZip Token Service (TokenService) API functionality
37
37
  __exportStar(require("./token-service"), exports);
38
38
  // Export package version (keep in sync with package.json version)
39
- exports.VERSION = '0.7.0';
39
+ exports.VERSION = '1.0.2';
40
40
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,97 @@
1
+ /**
2
+ * NeoZip Token Service account authentication HTTP client.
3
+ *
4
+ * Stateless functions for obtaining and renewing Token Service access tokens:
5
+ *
6
+ * POST /auth/register email verification (delivery: app|cli|browser)
7
+ * POST /auth/verify-email-code exchange a 6-digit code for an access token
8
+ * POST /auth/exchange-token exchange a magic-link token for an access token
9
+ * POST /auth/wallet-login/... silent SIWE-style renewal via wallet signature
10
+ * POST /auth/phone/request-otp Bearer; start phone verification
11
+ * POST /auth/phone/verify Bearer; complete phone verification
12
+ *
13
+ * These functions never persist credentials. Callers receive the access token
14
+ * (and parsed expiry) and are responsible for storing it.
15
+ */
16
+ /** How the Token Service formats the verification email for `/auth/register`. */
17
+ export type AccountVerificationDelivery = 'app' | 'cli' | 'browser';
18
+ export interface RegisterEmailResult {
19
+ success: boolean;
20
+ message?: string;
21
+ error?: string;
22
+ }
23
+ export interface AccessTokenResult {
24
+ accessToken: string;
25
+ email: string;
26
+ expiresAt: number | null;
27
+ }
28
+ /**
29
+ * Register an email for verification with a chosen delivery format.
30
+ *
31
+ * `app` sends a NeoZip deep link, `cli`/`browser` send a 6-digit code. The
32
+ * email is normalized (trimmed + lowercased) before sending.
33
+ */
34
+ export declare function registerEmailWithDelivery(baseUrl: string, email: string, verificationDelivery: AccountVerificationDelivery): Promise<RegisterEmailResult>;
35
+ /** Desktop-style registration (deep link email). */
36
+ export declare function registerEmailApp(baseUrl: string, email: string): Promise<RegisterEmailResult>;
37
+ /** Terminal / CLI registration (6-digit code only). */
38
+ export declare function registerEmailCli(baseUrl: string, email: string): Promise<RegisterEmailResult>;
39
+ /**
40
+ * Verify an emailed 6-digit code and return the issued access token.
41
+ *
42
+ * @throws {Error} when the code is invalid, the request fails, or the response
43
+ * contains no access token.
44
+ */
45
+ export declare function verifyEmailAndExtractToken(baseUrl: string, email: string, code: string): Promise<AccessTokenResult>;
46
+ /**
47
+ * Exchange a magic-link token for an access token.
48
+ *
49
+ * @throws {Error} when the token is invalid, the request fails, or the response
50
+ * is missing an access token or email.
51
+ */
52
+ export declare function exchangeMagicLinkToken(baseUrl: string, token: string): Promise<AccessTokenResult>;
53
+ /**
54
+ * Thrown when the Token Service does not expose the wallet-login endpoints
55
+ * (older deployment). Callers should fall back to interactive email re-auth.
56
+ */
57
+ export declare class WalletLoginUnavailableError extends Error {
58
+ constructor(message?: string);
59
+ }
60
+ /**
61
+ * Request a wallet-login challenge (first leg of silent, SIWE-style renewal).
62
+ *
63
+ * @throws {WalletLoginUnavailableError} when the endpoint returns 404.
64
+ * @throws {Error} on other failures or malformed responses.
65
+ */
66
+ export declare function requestWalletLoginChallenge(baseUrl: string, evmAddress: string): Promise<{
67
+ challengeId: string;
68
+ message: string;
69
+ evmAddress: string;
70
+ }>;
71
+ /**
72
+ * Complete a wallet-login challenge with a signature and receive an access
73
+ * token (second leg of silent renewal).
74
+ *
75
+ * @throws {WalletLoginUnavailableError} when the endpoint returns 404.
76
+ * @throws {Error} on other failures or when no access token is returned.
77
+ */
78
+ export declare function walletLogin(baseUrl: string, input: {
79
+ evmAddress: string;
80
+ challengeId: string;
81
+ evmSignature: string;
82
+ }): Promise<{
83
+ accessToken: string;
84
+ email: string | null;
85
+ expiresAt: number | null;
86
+ }>;
87
+ /** Start phone verification for the authenticated account (Bearer). */
88
+ export declare function requestPhoneOtp(baseUrl: string, accessToken: string, phoneE164: string): Promise<{
89
+ success: boolean;
90
+ error?: string;
91
+ }>;
92
+ /** Complete phone verification with the emailed/texted code (Bearer). */
93
+ export declare function verifyPhoneOtp(baseUrl: string, accessToken: string, phoneE164: string, code: string): Promise<{
94
+ success: boolean;
95
+ error?: string;
96
+ }>;
97
+ //# sourceMappingURL=TokenServiceAccountAuth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TokenServiceAccountAuth.d.ts","sourceRoot":"","sources":["../../src/token-service/TokenServiceAccountAuth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAYH,iFAAiF;AACjF,MAAM,MAAM,2BAA2B,GAAG,KAAK,GAAG,KAAK,GAAG,SAAS,CAAC;AAEpE,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,oBAAoB,EAAE,2BAA2B,GAChD,OAAO,CAAC,mBAAmB,CAAC,CAwB9B;AAED,oDAAoD;AACpD,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,mBAAmB,CAAC,CAE9B;AAED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ACzE,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAyB/C"}
@@ -0,0 +1,286 @@
1
+ "use strict";
2
+ /**
3
+ * NeoZip Token Service account authentication HTTP client.
4
+ *
5
+ * Stateless functions for obtaining and renewing Token Service access tokens:
6
+ *
7
+ * POST /auth/register email verification (delivery: app|cli|browser)
8
+ * POST /auth/verify-email-code exchange a 6-digit code for an access token
9
+ * POST /auth/exchange-token exchange a magic-link token for an access token
10
+ * POST /auth/wallet-login/... silent SIWE-style renewal via wallet signature
11
+ * POST /auth/phone/request-otp Bearer; start phone verification
12
+ * POST /auth/phone/verify Bearer; complete phone verification
13
+ *
14
+ * These functions never persist credentials. Callers receive the access token
15
+ * (and parsed expiry) and are responsible for storing it.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.WalletLoginUnavailableError = void 0;
19
+ exports.registerEmailWithDelivery = registerEmailWithDelivery;
20
+ exports.registerEmailApp = registerEmailApp;
21
+ exports.registerEmailCli = registerEmailCli;
22
+ exports.verifyEmailAndExtractToken = verifyEmailAndExtractToken;
23
+ exports.exchangeMagicLinkToken = exchangeMagicLinkToken;
24
+ exports.requestWalletLoginChallenge = requestWalletLoginChallenge;
25
+ exports.walletLogin = walletLogin;
26
+ exports.requestPhoneOtp = requestPhoneOtp;
27
+ exports.verifyPhoneOtp = verifyPhoneOtp;
28
+ const ethers_1 = require("ethers");
29
+ const http_1 = require("./http");
30
+ /**
31
+ * Register an email for verification with a chosen delivery format.
32
+ *
33
+ * `app` sends a NeoZip deep link, `cli`/`browser` send a 6-digit code. The
34
+ * email is normalized (trimmed + lowercased) before sending.
35
+ */
36
+ async function registerEmailWithDelivery(baseUrl, email, verificationDelivery) {
37
+ const url = (0, http_1.normalizeServerUrl)(baseUrl);
38
+ let res;
39
+ try {
40
+ res = await fetch(`${url}/auth/register`, {
41
+ method: 'POST',
42
+ headers: { 'content-type': 'application/json' },
43
+ body: JSON.stringify({
44
+ email: email.trim().toLowerCase(),
45
+ verificationDelivery,
46
+ }),
47
+ });
48
+ }
49
+ catch (err) {
50
+ return { success: false, error: (0, http_1.formatTokenServiceFetchError)(url, err) };
51
+ }
52
+ const parsed = await (0, http_1.safeJson)(res);
53
+ if (!res.ok || !parsed || parsed.success !== true) {
54
+ return { success: false, error: (0, http_1.extractError)(parsed, `HTTP ${res.status}`) };
55
+ }
56
+ return {
57
+ success: true,
58
+ message: typeof parsed.message === 'string' ? parsed.message : 'Verification email sent.',
59
+ };
60
+ }
61
+ /** Desktop-style registration (deep link email). */
62
+ async function registerEmailApp(baseUrl, email) {
63
+ return registerEmailWithDelivery(baseUrl, email, 'app');
64
+ }
65
+ /** Terminal / CLI registration (6-digit code only). */
66
+ async function registerEmailCli(baseUrl, email) {
67
+ return registerEmailWithDelivery(baseUrl, email, 'cli');
68
+ }
69
+ /**
70
+ * Verify an emailed 6-digit code and return the issued access token.
71
+ *
72
+ * @throws {Error} when the code is invalid, the request fails, or the response
73
+ * contains no access token.
74
+ */
75
+ async function verifyEmailAndExtractToken(baseUrl, email, code) {
76
+ const url = (0, http_1.normalizeServerUrl)(baseUrl);
77
+ let res;
78
+ try {
79
+ res = await fetch(`${url}/auth/verify-email-code`, {
80
+ method: 'POST',
81
+ headers: { 'content-type': 'application/json' },
82
+ body: JSON.stringify({ email: email.trim().toLowerCase(), code: code.trim() }),
83
+ });
84
+ }
85
+ catch (err) {
86
+ throw new Error((0, http_1.formatTokenServiceFetchError)(url, err));
87
+ }
88
+ const parsed = await (0, http_1.safeJson)(res);
89
+ if (!res.ok || !parsed || parsed.success !== true) {
90
+ throw new Error((0, http_1.extractError)(parsed, `Verification failed (HTTP ${res.status})`, {
91
+ status: res.status,
92
+ }));
93
+ }
94
+ const accessToken = (0, http_1.pickString)(parsed, 'accessToken', 'token', 'bearerToken');
95
+ if (!accessToken) {
96
+ throw new Error('Verification succeeded but no accessToken in response. Set NEOZIP_TOKEN_SERVICE_ACCESS_TOKEN manually or update the Token Service deployment.');
97
+ }
98
+ return {
99
+ accessToken,
100
+ email: (0, http_1.pickString)(parsed, 'email') ?? email.trim().toLowerCase(),
101
+ expiresAt: (0, http_1.parseAccessTokenExpiry)(parsed),
102
+ };
103
+ }
104
+ /**
105
+ * Exchange a magic-link token for an access token.
106
+ *
107
+ * @throws {Error} when the token is invalid, the request fails, or the response
108
+ * is missing an access token or email.
109
+ */
110
+ async function exchangeMagicLinkToken(baseUrl, token) {
111
+ const url = (0, http_1.normalizeServerUrl)(baseUrl);
112
+ let res;
113
+ try {
114
+ res = await fetch(`${url}/auth/exchange-token`, {
115
+ method: 'POST',
116
+ headers: { 'content-type': 'application/json' },
117
+ body: JSON.stringify({ token: token.trim() }),
118
+ });
119
+ }
120
+ catch (err) {
121
+ throw new Error((0, http_1.formatTokenServiceFetchError)(url, err));
122
+ }
123
+ const parsed = await (0, http_1.safeJson)(res);
124
+ if (!res.ok || !parsed || parsed.success !== true) {
125
+ throw new Error((0, http_1.extractError)(parsed, `Magic link exchange failed (HTTP ${res.status})`, {
126
+ status: res.status,
127
+ }));
128
+ }
129
+ const accessToken = (0, http_1.pickString)(parsed, 'accessToken', 'token', 'bearerToken');
130
+ if (!accessToken) {
131
+ throw new Error('Magic link exchange succeeded but no accessToken in response.');
132
+ }
133
+ const verifiedEmail = (0, http_1.pickString)(parsed, 'email');
134
+ if (!verifiedEmail) {
135
+ throw new Error('Magic link exchange succeeded but no email in response.');
136
+ }
137
+ return {
138
+ accessToken,
139
+ email: verifiedEmail,
140
+ expiresAt: (0, http_1.parseAccessTokenExpiry)(parsed),
141
+ };
142
+ }
143
+ /**
144
+ * Thrown when the Token Service does not expose the wallet-login endpoints
145
+ * (older deployment). Callers should fall back to interactive email re-auth.
146
+ */
147
+ class WalletLoginUnavailableError extends Error {
148
+ constructor(message = 'Token Service does not support wallet login') {
149
+ super(message);
150
+ this.name = 'WalletLoginUnavailableError';
151
+ }
152
+ }
153
+ exports.WalletLoginUnavailableError = WalletLoginUnavailableError;
154
+ /**
155
+ * Request a wallet-login challenge (first leg of silent, SIWE-style renewal).
156
+ *
157
+ * @throws {WalletLoginUnavailableError} when the endpoint returns 404.
158
+ * @throws {Error} on other failures or malformed responses.
159
+ */
160
+ async function requestWalletLoginChallenge(baseUrl, evmAddress) {
161
+ const url = (0, http_1.normalizeServerUrl)(baseUrl);
162
+ const checksummed = (0, ethers_1.getAddress)(evmAddress.trim());
163
+ let res;
164
+ try {
165
+ res = await fetch(`${url}/auth/wallet-login/challenge`, {
166
+ method: 'POST',
167
+ headers: { 'content-type': 'application/json' },
168
+ body: JSON.stringify({ evmAddress: checksummed }),
169
+ });
170
+ }
171
+ catch (err) {
172
+ throw new Error((0, http_1.formatTokenServiceFetchError)(url, err));
173
+ }
174
+ if (res.status === 404) {
175
+ throw new WalletLoginUnavailableError();
176
+ }
177
+ const parsed = await (0, http_1.safeJson)(res);
178
+ if (!res.ok || !parsed || parsed.success !== true) {
179
+ throw new Error((0, http_1.extractError)(parsed, `Wallet login challenge failed (HTTP ${res.status})`));
180
+ }
181
+ const challengeId = (0, http_1.pickString)(parsed, 'challengeId');
182
+ const message = (0, http_1.pickString)(parsed, 'message');
183
+ const addr = (0, http_1.pickString)(parsed, 'evmAddress');
184
+ if (!challengeId || !message || !addr) {
185
+ throw new Error('Wallet login challenge response missing fields');
186
+ }
187
+ return { challengeId, message, evmAddress: addr };
188
+ }
189
+ /**
190
+ * Complete a wallet-login challenge with a signature and receive an access
191
+ * token (second leg of silent renewal).
192
+ *
193
+ * @throws {WalletLoginUnavailableError} when the endpoint returns 404.
194
+ * @throws {Error} on other failures or when no access token is returned.
195
+ */
196
+ async function walletLogin(baseUrl, input) {
197
+ const url = (0, http_1.normalizeServerUrl)(baseUrl);
198
+ let res;
199
+ try {
200
+ res = await fetch(`${url}/auth/wallet-login`, {
201
+ method: 'POST',
202
+ headers: { 'content-type': 'application/json' },
203
+ body: JSON.stringify({
204
+ evmAddress: (0, ethers_1.getAddress)(input.evmAddress.trim()),
205
+ challengeId: input.challengeId,
206
+ evmSignature: input.evmSignature,
207
+ }),
208
+ });
209
+ }
210
+ catch (err) {
211
+ throw new Error((0, http_1.formatTokenServiceFetchError)(url, err));
212
+ }
213
+ if (res.status === 404) {
214
+ throw new WalletLoginUnavailableError();
215
+ }
216
+ const parsed = await (0, http_1.safeJson)(res);
217
+ if (!res.ok || !parsed || parsed.success !== true) {
218
+ throw new Error((0, http_1.extractError)(parsed, `Wallet login failed (HTTP ${res.status})`, { status: res.status }));
219
+ }
220
+ const accessToken = (0, http_1.pickString)(parsed, 'accessToken', 'token', 'bearerToken');
221
+ if (!accessToken) {
222
+ throw new Error('Wallet login succeeded but no accessToken in response.');
223
+ }
224
+ return {
225
+ accessToken,
226
+ email: (0, http_1.pickString)(parsed, 'email'),
227
+ expiresAt: (0, http_1.parseAccessTokenExpiry)(parsed),
228
+ };
229
+ }
230
+ /** Start phone verification for the authenticated account (Bearer). */
231
+ async function requestPhoneOtp(baseUrl, accessToken, phoneE164) {
232
+ const url = (0, http_1.normalizeServerUrl)(baseUrl);
233
+ let res;
234
+ try {
235
+ res = await fetch(`${url}/auth/phone/request-otp`, {
236
+ method: 'POST',
237
+ headers: {
238
+ Authorization: `Bearer ${accessToken}`,
239
+ 'content-type': 'application/json',
240
+ },
241
+ body: JSON.stringify({ phoneE164: phoneE164.trim() }),
242
+ });
243
+ }
244
+ catch (err) {
245
+ return { success: false, error: (0, http_1.formatTokenServiceFetchError)(url, err) };
246
+ }
247
+ const parsed = await (0, http_1.safeJson)(res);
248
+ if (!res.ok || !parsed || parsed.success !== true) {
249
+ return {
250
+ success: false,
251
+ error: (0, http_1.extractError)(parsed, `Phone OTP request failed (HTTP ${res.status})`, {
252
+ status: res.status,
253
+ }),
254
+ };
255
+ }
256
+ return { success: true };
257
+ }
258
+ /** Complete phone verification with the emailed/texted code (Bearer). */
259
+ async function verifyPhoneOtp(baseUrl, accessToken, phoneE164, code) {
260
+ const url = (0, http_1.normalizeServerUrl)(baseUrl);
261
+ let res;
262
+ try {
263
+ res = await fetch(`${url}/auth/phone/verify`, {
264
+ method: 'POST',
265
+ headers: {
266
+ Authorization: `Bearer ${accessToken}`,
267
+ 'content-type': 'application/json',
268
+ },
269
+ body: JSON.stringify({ phoneE164: phoneE164.trim(), code: code.trim() }),
270
+ });
271
+ }
272
+ catch (err) {
273
+ return { success: false, error: (0, http_1.formatTokenServiceFetchError)(url, err) };
274
+ }
275
+ const parsed = await (0, http_1.safeJson)(res);
276
+ if (!res.ok || !parsed || parsed.success !== true) {
277
+ return {
278
+ success: false,
279
+ error: (0, http_1.extractError)(parsed, `Phone verification failed (HTTP ${res.status})`, {
280
+ status: res.status,
281
+ }),
282
+ };
283
+ }
284
+ return { success: true };
285
+ }
286
+ //# sourceMappingURL=TokenServiceAccountAuth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TokenServiceAccountAuth.js","sourceRoot":"","sources":["../../src/token-service/TokenServiceAccountAuth.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAiCH,8DA4BC;AAGD,4CAKC;AAGD,4CAKC;AAQD,gEAmCC;AAQD,wDAoCC;AAmBD,kEA8BC;AASD,kCAqCC;AAGD,0CA6BC;AAGD,wCA8BC;AAlUD,mCAAoC;AACpC,iCAOgB;AAiBhB;;;;;GAKG;AACI,KAAK,UAAU,yBAAyB,CAC7C,OAAe,EACf,KAAa,EACb,oBAAiD;IAEjD,MAAM,GAAG,GAAG,IAAA,yBAAkB,EAAC,OAAO,CAAC,CAAC;IACxC,IAAI,GAAa,CAAC;IAClB,IAAI,CAAC;QACH,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,GAAG,gBAAgB,EAAE;YACxC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE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G,EAAE,CAAC;QACb,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAA,mCAA4B,EAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IAC3E,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,IAAA,eAAQ,EAA0B,GAAG,CAAC,CAAC;IAC5D,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;QAClD,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,IAAA,mBAAY,EAAC,MAAM,EAAE,mCAAmC,GAAG,CAAC,MAAM,GAAG,EAAE;gBAC5E,MAAM,EAAE,GAAG,CAAC,MAAM;aACnB,CAAC;SACH,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * NeoZip Token Service funding API client.
3
+ *
4
+ * The Token Service can disburse small native-gas grants to the user's primary
5
+ * linked Data Wallet so on-chain operations (tokenization, timestamping) can pay
6
+ * for gas. The recipient is server-authoritative — a client may only request a
7
+ * grant, never redirect it.
8
+ *
9
+ * GET /funding/policy?chainId=<id> (no auth)
10
+ * GET /funding/status?chainId=<id> (Bearer)
11
+ * POST /funding/request (Bearer, optional Idempotency-Key)
12
+ */
13
+ export interface FundingPolicy {
14
+ enabled: boolean;
15
+ grantWei: string;
16
+ grantEth: string;
17
+ cooldownHours: number;
18
+ lowBalanceWei?: string;
19
+ lowBalanceEth?: string;
20
+ }
21
+ export interface FundingPolicyResult {
22
+ chainId: number;
23
+ network: string;
24
+ policy: FundingPolicy;
25
+ }
26
+ export interface FundingGrantSummary {
27
+ id: number;
28
+ status: string;
29
+ amountWei: string;
30
+ amountEth: string;
31
+ transactionHash: string | null;
32
+ requestedAt: string;
33
+ confirmedAt: string | null;
34
+ }
35
+ export interface FundingStatusResult {
36
+ chainId: number;
37
+ recipientAddress: string | null;
38
+ enabled: boolean;
39
+ requiresPayment: boolean;
40
+ lastGrantAt: string | null;
41
+ nextEligibleAt: string | null;
42
+ recentGrants: FundingGrantSummary[];
43
+ }
44
+ export interface FundingRequestResult {
45
+ success: boolean;
46
+ status: string;
47
+ grantId: number;
48
+ amountWei: string;
49
+ amountEth: string;
50
+ recipientAddress: string;
51
+ transactionHash?: string | null;
52
+ paymentRequired?: boolean;
53
+ error?: string;
54
+ errorCode?: string;
55
+ }
56
+ /** Thrown when the Token Service does not expose the funding endpoints (older deployment). */
57
+ export declare class FundingUnavailableError extends Error {
58
+ constructor(message?: string);
59
+ }
60
+ /**
61
+ * Fetch the public funding policy for a chain (grant size, cooldown, low-balance
62
+ * threshold). No authentication required.
63
+ *
64
+ * @throws {FundingUnavailableError} when the endpoint returns 404.
65
+ * @throws {Error} on other failures or a malformed response.
66
+ */
67
+ export declare function getFundingPolicy(baseUrl: string, chainId: number): Promise<FundingPolicyResult>;
68
+ /**
69
+ * Fetch the caller's funding status for a chain (recipient address, eligibility,
70
+ * recent grants). Requires a Bearer access token.
71
+ *
72
+ * @throws {FundingUnavailableError} when the endpoint returns 404.
73
+ * @throws {Error} on other failures (including 401/403) or a malformed response.
74
+ */
75
+ export declare function getFundingStatus(baseUrl: string, accessToken: string, chainId: number): Promise<FundingStatusResult>;
76
+ /**
77
+ * Request a native-gas grant to the caller's primary Data Wallet. Requires a
78
+ * Bearer access token; an optional `idempotencyKey` makes retries safe.
79
+ *
80
+ * Returns the parsed result (which may itself report `success: false` with an
81
+ * `errorCode` such as a cooldown).
82
+ *
83
+ * @throws {FundingUnavailableError} when the endpoint returns 404.
84
+ * @throws {Error} when the response is non-JSON (e.g. auth failures).
85
+ */
86
+ export declare function requestFundingGrant(baseUrl: string, accessToken: string, chainId: number, idempotencyKey?: string): Promise<FundingRequestResult>;
87
+ //# sourceMappingURL=TokenServiceFunding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TokenService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