neozip-blockchain 0.7.2 → 0.8.0
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 +7 -7
- package/dist/token-service/TokenServiceAccountAuth.d.ts +97 -0
- package/dist/token-service/TokenServiceAccountAuth.d.ts.map +1 -0
- package/dist/token-service/TokenServiceAccountAuth.js +286 -0
- package/dist/token-service/TokenServiceAccountAuth.js.map +1 -0
- package/dist/token-service/TokenServiceFunding.d.ts +87 -0
- package/dist/token-service/TokenServiceFunding.d.ts.map +1 -0
- package/dist/token-service/TokenServiceFunding.js +143 -0
- package/dist/token-service/TokenServiceFunding.js.map +1 -0
- package/dist/token-service/TokenServiceIdentity.d.ts +96 -0
- package/dist/token-service/TokenServiceIdentity.d.ts.map +1 -0
- package/dist/token-service/TokenServiceIdentity.js +240 -0
- package/dist/token-service/TokenServiceIdentity.js.map +1 -0
- package/dist/token-service/http.d.ts +46 -0
- package/dist/token-service/http.d.ts.map +1 -0
- package/dist/token-service/http.js +119 -0
- package/dist/token-service/http.js.map +1 -0
- package/dist/token-service/index.d.ts +4 -0
- package/dist/token-service/index.d.ts.map +1 -1
- package/dist/token-service/index.js +42 -1
- package/dist/token-service/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ This package provides the client-side API and utilities that work with the sibli
|
|
|
25
25
|
```bash
|
|
26
26
|
npm install neozip-blockchain
|
|
27
27
|
# or
|
|
28
|
-
|
|
28
|
+
pnpm add neozip-blockchain
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
For full NZIP creation and verification you typically use **neozipkit** together with this package:
|
|
@@ -185,24 +185,24 @@ MIT License - see [LICENSE](LICENSE) for details.
|
|
|
185
185
|
|
|
186
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.
|
|
187
187
|
|
|
188
|
-
Preview what will ship: run **`
|
|
188
|
+
Preview what will ship: run **`pnpm publish:dry-run`** (it uses **`npm publish --dry-run`**, which matches npm’s file list).
|
|
189
189
|
|
|
190
190
|
## Development
|
|
191
191
|
|
|
192
192
|
This package is part of the [neozipkit monorepo](../../README.md). From the **repository root**:
|
|
193
193
|
|
|
194
194
|
```bash
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
195
|
+
pnpm install
|
|
196
|
+
pnpm build # builds neozipkit first, then neozip-blockchain
|
|
197
|
+
pnpm test:unit
|
|
198
198
|
```
|
|
199
199
|
|
|
200
200
|
To work on this package alone:
|
|
201
201
|
|
|
202
202
|
```bash
|
|
203
203
|
cd packages/neozip-blockchain
|
|
204
|
-
|
|
205
|
-
|
|
204
|
+
pnpm build
|
|
205
|
+
pnpm test
|
|
206
206
|
```
|
|
207
207
|
|
|
208
208
|
See the [monorepo README](../../README.md) for version management and release workflow.
|
|
@@ -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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AAM,EACf,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CA2BvE;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,GACvE,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,CAkClF;AAED,uEAAuE;AACvE,wBAAsB,eAAe,CACnC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAyB/C;AAED,yEAAyE;AACzE,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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M,KAAK,CAAC,GAAG,GAAG,oBAAoB,EAAE;YAC5C,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,WAAW,EAAE;gBACtC,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;SACzE,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,GAAG,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":"TokenServiceFunding.d.ts","sourceRoot":"","sources":["../../src/token-service/TokenServiceFunding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAUH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB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