@witnium-tech/witniumchain 0.3.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/README.md.bak DELETED
@@ -1,160 +0,0 @@
1
- # @witnium-tech/witniumchain
2
-
3
- TypeScript SDK for the WitniumChain accounts service — identity, billing,
4
- organisation administration, OAuth sessions, and delegated-signing-key
5
- management.
6
-
7
- ## Status
8
-
9
- **v0.1 — low-level "shell" client.** One method per OpenAPI route, five
10
- auth modes selectable on a single client. Thread 4 of Phase C will layer
11
- three higher-level clients on top:
12
-
13
- - `WitniumAccountsClient` (end-user) — wraps signup, login, subscriptions,
14
- delegated-key one-call provisioning, account management.
15
- - `WitniumAccountsOrgClient` (org admin) — wraps user provisioning, Stripe
16
- Connect onboarding.
17
- - `WitniumAccountsAdminClient` (sysadmin) — wraps org lifecycle, key
18
- rotation, credit adjustment.
19
-
20
- For now, this shell client is what's published. Every type comes from the
21
- OpenAPI spec via `openapi-typescript`; a CI drift test in the parent repo
22
- gates regeneration on every change.
23
-
24
- ## Install
25
-
26
- ```bash
27
- npm install @witnium-tech/witniumchain
28
- ```
29
-
30
- ## Auth model
31
-
32
- The accounts service accepts five distinct credentials. Configure whichever
33
- you need on the client; methods that require a credential you didn't supply
34
- throw at call time.
35
-
36
- | Credential | Header / Cookie | Used by |
37
- |---|---|---|
38
- | `sessionCookie` | `Cookie: wac_session=…` | `/v1/auth/logout`, `/v1/account/*`, `/v1/billing/*`, `/v1/keys/*`, `/v1/contracts/{pause,unpause}`, `/v1/oauth/sessions*` |
39
- | `accessToken` | `Authorization: Bearer <JWT>` | `/v1/users/me/delegated-keys/*`, `/v1/sign` |
40
- | `orgApiKey` | `Authorization: Bearer wcorg_live_…` | `/v1/orgs/me/*` |
41
- | `adminToken` | `Authorization: Bearer <ADMIN_TOKEN>` | `/v1/admin/*` |
42
- | `signedRequest` | `X-Witnium-Key/Timestamp/Signature` | `/v1/contracts/{addr}/witnesses/{propose,sign,finalize,revoke}` |
43
-
44
- Public routes need no credential (`/v1/auth/{signup,verify,login,…}`,
45
- `/v1/contracts/provision`, `GET /v1/contracts/{addr}/witnesses/{id}`,
46
- `/health/*`).
47
-
48
- ## Examples
49
-
50
- ### End-user signup + login
51
-
52
- ```ts
53
- import { WitniumAccountsClient } from '@witnium-tech/witniumchain';
54
-
55
- const client = new WitniumAccountsClient({
56
- baseUrl: 'https://auth.witniumchain.com',
57
- });
58
-
59
- await client.signup({ email: 'alice@example.com', password: 'correct horse battery staple' });
60
- // User clicks email link, lands on /verify?token=…
61
- const { provisioningToken } = await client.verifyEmail('the-token-from-the-link');
62
-
63
- // Then login (sets the wac_session cookie in a browser; in Node, capture
64
- // from response headers and pass back via `sessionCookie`).
65
- await client.login({ email: 'alice@example.com', password: '…' });
66
- ```
67
-
68
- ### Org admin — create a user
69
-
70
- ```ts
71
- const org = new WitniumAccountsClient({
72
- baseUrl: 'https://auth.witniumchain.com',
73
- orgApiKey: 'wcorg_live_…',
74
- });
75
-
76
- const { userId, provisioningToken } = await org.createOrgUser({
77
- email: 'bob@customer.example.com',
78
- });
79
- // Forward `provisioningToken` to Bob — he calls /v1/contracts/provision
80
- // with locally-generated owner + signing keypairs.
81
- ```
82
-
83
- ### Sysadmin — create an organisation
84
-
85
- ```ts
86
- const sys = new WitniumAccountsClient({
87
- baseUrl: 'https://auth.witniumchain.com',
88
- adminToken: process.env.ACCOUNTS_ADMIN_TOKEN!,
89
- });
90
-
91
- const { organization, apiKey } = await sys.createOrganization({
92
- name: 'Acme Inc.',
93
- email: 'ops@acme.example.com',
94
- accountType: 'metered',
95
- signupGrantAmount: 100,
96
- });
97
- // `apiKey` is shown ONCE — store it now.
98
- ```
99
-
100
- ### OAuth API — delegated-key + sign
101
-
102
- ```ts
103
- const api = new WitniumAccountsClient({
104
- baseUrl: 'https://auth.witniumchain.com',
105
- accessToken: bearerJwt,
106
- });
107
-
108
- const prepared = await api.prepareDelegatedKey({ contractAddress: '0x…' });
109
- // Sign prepared.messageToSign with your owner key locally:
110
- const ownerSignature = await myOwnerSigner.sign(prepared.messageToSign);
111
-
112
- const submitted = await api.submitDelegatedKey(prepared.id, { ownerSignature });
113
- // submitted.confirmed === true once the addSigningKey tx mines (~10–15 s).
114
-
115
- const { signature } = await api.sign(
116
- { delegatedKeyId: prepared.id, payload: 'deadbeef…' },
117
- );
118
- ```
119
-
120
- ### SDK signed-request (witness propose/sign/finalize)
121
-
122
- ```ts
123
- const sdk = new WitniumAccountsClient({
124
- baseUrl: 'https://auth.witniumchain.com',
125
- signedRequest: {
126
- publicKeyHex: 'abcd…64-chars…',
127
- sign: async (canonicalMessage) => {
128
- // Sign with your Ed25519 key — e.g. via @noble/ed25519 or a KMS.
129
- // Return the 128-char hex signature.
130
- return await myEd25519Sign(canonicalMessage);
131
- },
132
- },
133
- });
134
-
135
- const intent = await sdk.proposeWitness('0x…', {
136
- dataId: '…64-hex…',
137
- requiredSigners: ['…signer-pubkey…'],
138
- });
139
- ```
140
-
141
- ## Errors
142
-
143
- All non-2xx responses surface as `WitniumAccountsApiError`:
144
-
145
- ```ts
146
- import { WitniumAccountsApiError } from '@witnium-tech/witniumchain';
147
-
148
- try {
149
- await client.createOrgUser({ email: 'taken@example.com' });
150
- } catch (err) {
151
- if (err instanceof WitniumAccountsApiError) {
152
- console.error(err.status, err.errorLabel, err.message);
153
- // err.body holds the raw parsed body for advanced inspection.
154
- }
155
- }
156
- ```
157
-
158
- ## License
159
-
160
- MIT.