@witnium-tech/witniumchain 0.5.0 → 0.6.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/FRONTEND-INTEGRATION.md +265 -0
- package/dist/index.d.mts +215 -9
- package/dist/index.d.ts +215 -9
- package/dist/index.js +114 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +114 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -5
package/dist/index.mjs
CHANGED
|
@@ -155,6 +155,19 @@ var WitniumchainClient = class {
|
|
|
155
155
|
signup(body) {
|
|
156
156
|
return this.req("POST", "/v1/auth/signup", { auth: "Public", body });
|
|
157
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Self-serve org creation (Phase RBAC Thread D). One public call that
|
|
160
|
+
* creates the admin user, the org, the org-admin membership, and deploys
|
|
161
|
+
* the contract with the caller's client-generated `ownerPublicKey` +
|
|
162
|
+
* `initialSigningPublicKey`. Witnium never sees the private bytes.
|
|
163
|
+
*
|
|
164
|
+
* Returns `{ orgId, userId, contractAddress, contractVersion,
|
|
165
|
+
* emailVerifyToken }`. The verify token is also emailed; it's echoed here
|
|
166
|
+
* for UIs that prefer to render the verify link themselves.
|
|
167
|
+
*/
|
|
168
|
+
createOrg(body) {
|
|
169
|
+
return this.req("POST", "/v1/orgs", { auth: "Public", body });
|
|
170
|
+
}
|
|
158
171
|
verifyEmail(token) {
|
|
159
172
|
return this.req("GET", "/v1/auth/verify", {
|
|
160
173
|
auth: "Public",
|
|
@@ -1344,6 +1357,106 @@ var WitniumchainAdminClient = class {
|
|
|
1344
1357
|
}
|
|
1345
1358
|
};
|
|
1346
1359
|
|
|
1360
|
+
// src/chain-admin-client.ts
|
|
1361
|
+
var WitniumchainChainAdminClient = class {
|
|
1362
|
+
baseUrl;
|
|
1363
|
+
adminToken;
|
|
1364
|
+
adminTokenProvider;
|
|
1365
|
+
timeout;
|
|
1366
|
+
fetchImpl;
|
|
1367
|
+
constructor(config) {
|
|
1368
|
+
if (!config.baseUrl) {
|
|
1369
|
+
throw new Error("WitniumchainChainAdminClient: baseUrl is required");
|
|
1370
|
+
}
|
|
1371
|
+
if (config.adminToken && config.adminTokenProvider) {
|
|
1372
|
+
throw new Error(
|
|
1373
|
+
"WitniumchainChainAdminClient: pass either adminToken (static) or adminTokenProvider (OAuth), not both"
|
|
1374
|
+
);
|
|
1375
|
+
}
|
|
1376
|
+
if (!config.adminToken && !config.adminTokenProvider) {
|
|
1377
|
+
throw new Error(
|
|
1378
|
+
"WitniumchainChainAdminClient: one of adminToken or adminTokenProvider is required"
|
|
1379
|
+
);
|
|
1380
|
+
}
|
|
1381
|
+
this.baseUrl = config.baseUrl.replace(/\/+$/, "");
|
|
1382
|
+
this.adminToken = config.adminToken;
|
|
1383
|
+
this.adminTokenProvider = config.adminTokenProvider;
|
|
1384
|
+
this.timeout = config.timeout ?? 3e4;
|
|
1385
|
+
this.fetchImpl = config.fetch ?? globalThis.fetch;
|
|
1386
|
+
}
|
|
1387
|
+
async deployContract(body) {
|
|
1388
|
+
return this.req("POST", "/v5/contracts/deploy", body);
|
|
1389
|
+
}
|
|
1390
|
+
async addSigningKey(contractAddress, body) {
|
|
1391
|
+
return this.req(
|
|
1392
|
+
"POST",
|
|
1393
|
+
`/v5/contracts/${encodeURIComponent(contractAddress)}/keys`,
|
|
1394
|
+
body
|
|
1395
|
+
);
|
|
1396
|
+
}
|
|
1397
|
+
async revokeSigningKey(contractAddress, body) {
|
|
1398
|
+
return this.req(
|
|
1399
|
+
"POST",
|
|
1400
|
+
`/v5/contracts/${encodeURIComponent(contractAddress)}/keys/revoke`,
|
|
1401
|
+
body
|
|
1402
|
+
);
|
|
1403
|
+
}
|
|
1404
|
+
async pauseContract(contractAddress, body) {
|
|
1405
|
+
return this.req(
|
|
1406
|
+
"POST",
|
|
1407
|
+
`/v5/contracts/${encodeURIComponent(contractAddress)}/pause`,
|
|
1408
|
+
body
|
|
1409
|
+
);
|
|
1410
|
+
}
|
|
1411
|
+
async unpauseContract(contractAddress, body) {
|
|
1412
|
+
return this.req(
|
|
1413
|
+
"POST",
|
|
1414
|
+
`/v5/contracts/${encodeURIComponent(contractAddress)}/unpause`,
|
|
1415
|
+
body
|
|
1416
|
+
);
|
|
1417
|
+
}
|
|
1418
|
+
async resolveToken() {
|
|
1419
|
+
if (this.adminTokenProvider) return this.adminTokenProvider();
|
|
1420
|
+
return this.adminToken;
|
|
1421
|
+
}
|
|
1422
|
+
async req(method, path, body) {
|
|
1423
|
+
const token = await this.resolveToken();
|
|
1424
|
+
const controller = new AbortController();
|
|
1425
|
+
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
1426
|
+
try {
|
|
1427
|
+
const response = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
1428
|
+
method,
|
|
1429
|
+
headers: {
|
|
1430
|
+
accept: "application/json",
|
|
1431
|
+
"content-type": "application/json",
|
|
1432
|
+
authorization: `Bearer ${token}`
|
|
1433
|
+
},
|
|
1434
|
+
body: JSON.stringify(body),
|
|
1435
|
+
signal: controller.signal
|
|
1436
|
+
});
|
|
1437
|
+
const text = await response.text();
|
|
1438
|
+
const parsed = text ? safeParse(text) : void 0;
|
|
1439
|
+
if (!response.ok) {
|
|
1440
|
+
throw new WitniumchainApiError({
|
|
1441
|
+
status: response.status,
|
|
1442
|
+
message: parsed?.message ?? `${method} ${path} failed: ${response.status}`,
|
|
1443
|
+
body: parsed
|
|
1444
|
+
});
|
|
1445
|
+
}
|
|
1446
|
+
return parsed;
|
|
1447
|
+
} finally {
|
|
1448
|
+
clearTimeout(timer);
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
};
|
|
1452
|
+
function safeParse(text) {
|
|
1453
|
+
try {
|
|
1454
|
+
return JSON.parse(text);
|
|
1455
|
+
} catch {
|
|
1456
|
+
return text;
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1347
1460
|
// src/org-client.ts
|
|
1348
1461
|
var WitniumchainOrgClient = class {
|
|
1349
1462
|
inner;
|
|
@@ -1390,6 +1503,6 @@ var OrgUsers = class {
|
|
|
1390
1503
|
}
|
|
1391
1504
|
};
|
|
1392
1505
|
|
|
1393
|
-
export { DelegatedKeys, MfaNamespace, MfaRecoveryCodes, MfaTotp, OauthNamespace, OauthSessions, OrgUsers, SigningKeys, Subscriptions, WitniumchainAdminClient, WitniumchainApiError, WitniumchainClient, WitniumchainOrgClient, defaultVerifierStorage };
|
|
1506
|
+
export { DelegatedKeys, MfaNamespace, MfaRecoveryCodes, MfaTotp, OauthNamespace, OauthSessions, OrgUsers, SigningKeys, Subscriptions, WitniumchainAdminClient, WitniumchainApiError, WitniumchainChainAdminClient, WitniumchainClient, WitniumchainOrgClient, defaultVerifierStorage };
|
|
1394
1507
|
//# sourceMappingURL=index.mjs.map
|
|
1395
1508
|
//# sourceMappingURL=index.mjs.map
|