@aithos/sdk 0.1.0-alpha.4 → 0.1.0-alpha.40
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 +211 -7
- package/dist/src/assets.d.ts +207 -0
- package/dist/src/assets.js +533 -0
- package/dist/src/auth-api.d.ts +138 -0
- package/dist/src/auth-api.js +168 -0
- package/dist/src/auth.d.ts +536 -119
- package/dist/src/auth.js +1207 -152
- package/dist/src/compute.d.ts +221 -9
- package/dist/src/compute.js +293 -16
- package/dist/src/data-schema-contacts-v1.d.ts +14 -0
- package/dist/src/data-schema-contacts-v1.js +28 -0
- package/dist/src/data.d.ts +153 -0
- package/dist/src/data.js +670 -0
- package/dist/src/endpoints.d.ts +9 -0
- package/dist/src/endpoints.js +5 -0
- package/dist/src/ethos.d.ts +202 -1
- package/dist/src/ethos.js +821 -16
- package/dist/src/index.d.ts +16 -6
- package/dist/src/index.js +33 -6
- package/dist/src/internal/delegate-bundle.d.ts +18 -0
- package/dist/src/internal/delegate-bundle.js +94 -0
- package/dist/src/internal/delegate-state.d.ts +45 -0
- package/dist/src/internal/delegate-state.js +120 -0
- package/dist/src/internal/envelope.d.ts +77 -0
- package/dist/src/internal/envelope.js +154 -0
- package/dist/src/internal/owner-signers.d.ts +78 -0
- package/dist/src/internal/owner-signers.js +179 -0
- package/dist/src/internal/protocol-client-bridge.d.ts +8 -0
- package/dist/src/internal/protocol-client-bridge.js +20 -0
- package/dist/src/internal/recovery-file.d.ts +29 -0
- package/dist/src/internal/recovery-file.js +98 -0
- package/dist/src/internal/signer.d.ts +59 -0
- package/dist/src/internal/signer.js +86 -0
- package/dist/src/key-store.d.ts +128 -0
- package/dist/src/key-store.js +244 -0
- package/dist/src/mandates.d.ts +163 -1
- package/dist/src/mandates.js +286 -8
- package/dist/src/react/AithosAsset.d.ts +66 -0
- package/dist/src/react/AithosAsset.js +67 -0
- package/dist/src/react/context.d.ts +29 -0
- package/dist/src/react/context.js +31 -0
- package/dist/src/react/index.d.ts +28 -0
- package/dist/src/react/index.js +30 -0
- package/dist/src/react/use-aithos-asset.d.ts +39 -0
- package/dist/src/react/use-aithos-asset.js +118 -0
- package/dist/src/sdk.d.ts +39 -3
- package/dist/src/sdk.js +36 -23
- package/dist/src/wallet.d.ts +4 -6
- package/dist/src/wallet.js +18 -8
- package/dist/src/web.d.ts +279 -0
- package/dist/src/web.js +186 -0
- package/package.json +18 -3
- package/dist/test/auth.test.d.ts +0 -2
- package/dist/test/auth.test.js +0 -175
- package/dist/test/compute.test.d.ts +0 -2
- package/dist/test/compute.test.js +0 -179
- package/dist/test/endpoints.test.d.ts +0 -2
- package/dist/test/endpoints.test.js +0 -43
- package/dist/test/sdk.test.d.ts +0 -2
- package/dist/test/sdk.test.js +0 -86
- package/dist/test/wallet.test.d.ts +0 -2
- package/dist/test/wallet.test.js +0 -110
package/dist/src/auth-api.js
CHANGED
|
@@ -41,6 +41,19 @@ async function postJson(http, path, body, jwt) {
|
|
|
41
41
|
throw await readError(res, "request_failed");
|
|
42
42
|
return (await res.json());
|
|
43
43
|
}
|
|
44
|
+
async function putJson(http, path, body, jwt) {
|
|
45
|
+
const res = await http.fetchImpl(`${http.authBaseUrl}${path}`, {
|
|
46
|
+
method: "PUT",
|
|
47
|
+
headers: {
|
|
48
|
+
"content-type": "application/json",
|
|
49
|
+
authorization: `Bearer ${jwt}`,
|
|
50
|
+
},
|
|
51
|
+
body: JSON.stringify(body),
|
|
52
|
+
});
|
|
53
|
+
if (!res.ok)
|
|
54
|
+
throw await readError(res, "request_failed");
|
|
55
|
+
return (await res.json());
|
|
56
|
+
}
|
|
44
57
|
export async function registerAccount(http, input) {
|
|
45
58
|
return postJson(http, "/auth/register", {
|
|
46
59
|
email: input.email,
|
|
@@ -56,6 +69,13 @@ export async function registerAccount(http, input) {
|
|
|
56
69
|
blob_version: input.blobVersion,
|
|
57
70
|
});
|
|
58
71
|
}
|
|
72
|
+
export async function putBlob(http, input) {
|
|
73
|
+
return putJson(http, "/auth/blob", {
|
|
74
|
+
blob_b64: bytesToB64(input.blob),
|
|
75
|
+
blob_nonce_b64: bytesToB64(input.blobNonce),
|
|
76
|
+
blob_version: input.blobVersion,
|
|
77
|
+
}, input.jwt);
|
|
78
|
+
}
|
|
59
79
|
export async function loginChallenge(http, email) {
|
|
60
80
|
const wire = await postJson(http, "/auth/login/challenge", { email });
|
|
61
81
|
return {
|
|
@@ -79,4 +99,152 @@ export async function loginVerify(http, email, authKey) {
|
|
|
79
99
|
blobVersion: wire.blob_version,
|
|
80
100
|
};
|
|
81
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Provision a custodial-mode account on behalf of a registered app.
|
|
104
|
+
*
|
|
105
|
+
* Two integration paths:
|
|
106
|
+
* - **Backend** caller passes `apiKey` (server-only secret).
|
|
107
|
+
* - **Browser** caller passes `publicKey` (safe to ship in the bundle).
|
|
108
|
+
* The browser also sends its `Origin` header automatically and the
|
|
109
|
+
* auth backend validates it against the app's allowed_origins list.
|
|
110
|
+
*
|
|
111
|
+
* On success the account exists in DDB with `email_verified: false` and
|
|
112
|
+
* the response carries `status: "pending_verification"` — call
|
|
113
|
+
* {@link custodialVerifyEmail} after the user clicks the confirmation
|
|
114
|
+
* link before attempting sign-in.
|
|
115
|
+
*/
|
|
116
|
+
export async function custodialSignUp(http, input) {
|
|
117
|
+
if (!input.apiKey && !input.publicKey) {
|
|
118
|
+
throw new AithosSDKError("auth_missing_api_key", "signUpCustodial requires either apiKey or publicKey");
|
|
119
|
+
}
|
|
120
|
+
if (input.apiKey && input.publicKey) {
|
|
121
|
+
throw new AithosSDKError("auth_invalid_input", "signUpCustodial: pass exactly one of apiKey or publicKey, not both");
|
|
122
|
+
}
|
|
123
|
+
const bearer = (input.apiKey ?? input.publicKey);
|
|
124
|
+
const res = await http.fetchImpl(`${http.authBaseUrl}/auth/custodial/sign-up`, {
|
|
125
|
+
method: "POST",
|
|
126
|
+
headers: {
|
|
127
|
+
"content-type": "application/json",
|
|
128
|
+
authorization: `Bearer ${bearer}`,
|
|
129
|
+
},
|
|
130
|
+
body: JSON.stringify({
|
|
131
|
+
email: input.email,
|
|
132
|
+
password: input.password,
|
|
133
|
+
...(input.displayName ? { display_name: input.displayName } : {}),
|
|
134
|
+
...(input.handleHint ? { handle_hint: input.handleHint } : {}),
|
|
135
|
+
}),
|
|
136
|
+
});
|
|
137
|
+
if (!res.ok)
|
|
138
|
+
throw await readError(res, "custodial_signup_failed");
|
|
139
|
+
const wire = (await res.json());
|
|
140
|
+
return {
|
|
141
|
+
status: "pending_verification",
|
|
142
|
+
email: wire.email,
|
|
143
|
+
mailSent: wire.mail_sent,
|
|
144
|
+
...(wire.mail_message_id !== undefined
|
|
145
|
+
? { mailMessageId: wire.mail_message_id }
|
|
146
|
+
: {}),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Consume the verification token from the confirmation link. On a fresh
|
|
151
|
+
* click: returns a full session payload (magic-link auto-signin). On a
|
|
152
|
+
* replayed click of an already-consumed link: returns
|
|
153
|
+
* `{ status: "already_verified" }`.
|
|
154
|
+
*
|
|
155
|
+
* Throws `auth_token_invalid_or_expired` if the token is wrong, consumed,
|
|
156
|
+
* or past its TTL.
|
|
157
|
+
*/
|
|
158
|
+
export async function custodialVerifyEmail(http, input) {
|
|
159
|
+
const res = await http.fetchImpl(`${http.authBaseUrl}/auth/custodial/verify`, {
|
|
160
|
+
method: "POST",
|
|
161
|
+
headers: { "content-type": "application/json" },
|
|
162
|
+
body: JSON.stringify({ email: input.email, token: input.token }),
|
|
163
|
+
});
|
|
164
|
+
if (!res.ok)
|
|
165
|
+
throw await readError(res, "custodial_verify_failed");
|
|
166
|
+
const wire = (await res.json());
|
|
167
|
+
if (wire.status === "already_verified") {
|
|
168
|
+
return { status: "already_verified", email: wire.email };
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
status: "signed_in",
|
|
172
|
+
session: wire.session,
|
|
173
|
+
exp: wire.exp,
|
|
174
|
+
did: wire.did,
|
|
175
|
+
handle: wire.handle,
|
|
176
|
+
displayName: wire.display_name,
|
|
177
|
+
seed: b64ToBytes(wire.seed_b64),
|
|
178
|
+
encKey: b64ToBytes(wire.enc_key_b64),
|
|
179
|
+
blob: wire.blob_b64 ? b64ToBytes(wire.blob_b64) : new Uint8Array(0),
|
|
180
|
+
blobNonce: wire.blob_nonce_b64
|
|
181
|
+
? b64ToBytes(wire.blob_nonce_b64)
|
|
182
|
+
: new Uint8Array(0),
|
|
183
|
+
blobVersion: wire.blob_version,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/* ---- POST /auth/custodial/verify/resend -------------------------------- */
|
|
187
|
+
/** Re-send the verification mail for a pending account. The backend
|
|
188
|
+
* is anti-enum (always 200) and rate-limited 1/h/account, so this is
|
|
189
|
+
* safe to call even when the user state is unknown. Accepts the same
|
|
190
|
+
* credential families as {@link custodialSignUp}. */
|
|
191
|
+
export async function custodialResendVerify(http, args) {
|
|
192
|
+
if (!args.apiKey && !args.publicKey) {
|
|
193
|
+
throw new AithosSDKError("auth_missing_api_key", "resendVerificationEmail requires either apiKey or publicKey");
|
|
194
|
+
}
|
|
195
|
+
const bearer = (args.apiKey ?? args.publicKey);
|
|
196
|
+
const res = await http.fetchImpl(`${http.authBaseUrl}/auth/custodial/verify/resend`, {
|
|
197
|
+
method: "POST",
|
|
198
|
+
headers: {
|
|
199
|
+
"content-type": "application/json",
|
|
200
|
+
authorization: `Bearer ${bearer}`,
|
|
201
|
+
},
|
|
202
|
+
body: JSON.stringify({ email: args.email }),
|
|
203
|
+
});
|
|
204
|
+
if (!res.ok)
|
|
205
|
+
throw await readError(res, "custodial_resend_failed");
|
|
206
|
+
}
|
|
207
|
+
export async function custodialSignIn(http, input) {
|
|
208
|
+
const wire = await postJson(http, "/auth/custodial/sign-in", { email: input.email, password: input.password });
|
|
209
|
+
return {
|
|
210
|
+
session: wire.session,
|
|
211
|
+
exp: wire.exp,
|
|
212
|
+
did: wire.did,
|
|
213
|
+
handle: wire.handle,
|
|
214
|
+
displayName: wire.display_name,
|
|
215
|
+
seed: b64ToBytes(wire.seed_b64),
|
|
216
|
+
encKey: b64ToBytes(wire.enc_key_b64),
|
|
217
|
+
blob: wire.blob_b64 ? b64ToBytes(wire.blob_b64) : new Uint8Array(0),
|
|
218
|
+
blobNonce: wire.blob_nonce_b64
|
|
219
|
+
? b64ToBytes(wire.blob_nonce_b64)
|
|
220
|
+
: new Uint8Array(0),
|
|
221
|
+
blobVersion: wire.blob_version,
|
|
222
|
+
passwordMustChange: wire.password_must_change,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/* ---- POST /auth/custodial/reset/request --------------------------------- */
|
|
226
|
+
export async function custodialResetRequest(http, email) {
|
|
227
|
+
// Backend always returns 200 { ok: true } regardless. We accept any
|
|
228
|
+
// 2xx body, even non-JSON, to be defensive.
|
|
229
|
+
const res = await http.fetchImpl(`${http.authBaseUrl}/auth/custodial/reset/request`, {
|
|
230
|
+
method: "POST",
|
|
231
|
+
headers: { "content-type": "application/json" },
|
|
232
|
+
body: JSON.stringify({ email }),
|
|
233
|
+
});
|
|
234
|
+
if (!res.ok)
|
|
235
|
+
throw await readError(res, "custodial_reset_request_failed");
|
|
236
|
+
}
|
|
237
|
+
export async function custodialResetFinalize(http, input) {
|
|
238
|
+
const wire = await postJson(http, "/auth/custodial/reset/finalize", {
|
|
239
|
+
email: input.email,
|
|
240
|
+
token: input.token,
|
|
241
|
+
new_password: input.newPassword,
|
|
242
|
+
});
|
|
243
|
+
return {
|
|
244
|
+
session: wire.session,
|
|
245
|
+
exp: wire.exp,
|
|
246
|
+
did: wire.did,
|
|
247
|
+
handle: wire.handle,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
82
250
|
//# sourceMappingURL=auth-api.js.map
|