You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Reject non-integer secret in verify
- Rename getHash to generate in API, docs, and tests
- Enforce 0..1e10 range and strict equality in verify (fix 32-bit false accept)
- Update README and USAGE for default export and generate flow
- Update deno.json and package.json description and keywords
Create an instance with a **connector ID** (e.g. service URL or app identifier). Generate a one-time **hashId**, build a **requestId**, then decode to a numeric code or verify with a user secret.
40
+
Use a **connector ID** (e.g. service URL or app identifier) on both sides. Generate a one-time **hashId**, create an **instance**, build a **requestId**, then decode to a numeric code or verify with a user secret.
// Instance for connector (same on client and verifier)
31
+
const instance =trustless.create(connectorId)
32
+
33
+
// Request with 10s expiry window; send requestId to verifier (QR / link / form)
32
34
const requestId =instance.request(hashId, 10)
33
35
34
36
// Decode to code, or null if invalid/expired
@@ -41,66 +43,67 @@ if (codeId !== null) {
41
43
42
44
## Flow Overview
43
45
44
-
1.**Connector** — Both client and verifier use the same `connectorId` (e.g. service URL). Each creates `Trustless.create(connectorId)`.
45
-
2.**Hash** — Client calls `Trustless.getHash(connectorId)` once per session; returns a 197-char hex `hashId` (unique per call).
46
-
3.**Request** — Client calls `instance.request(hashId, expireTime?)` to get `requestId` (encoded payload with time slot and window). Send `requestId` (e.g. QR, link, form).
47
-
4.**Decode** — Verifier has `hashId` (e.g. stored or passed with the request). Verifier calls `instance.decode(hashId, requestId)` to get numeric `codeId`, or `null` if invalid/expired.
48
-
5.**Verify** — User enters the code (or it’s shown). Verifier calls `instance.verify(requestId, secret)` with that value; returns `true` when not expired and code matches.
46
+
1.**Connector** — Both client and verifier use the same `connectorId` (e.g. service URL).
47
+
2.**Hash** — Client calls `trustless.generate(connectorId)` once per session; returns a 197-char hex `hashId` (unique per call). This is the session identifier.
48
+
3.**Instance** — Both sides call `trustless.create(connectorId)` to get an instance bound to that connector.
49
+
4.**Request** — Client calls `instance.request(hashId, expireTime?)` to get `requestId`. Send `requestId` and `hashId` to the verifier (e.g. QR, link, form).
50
+
5.**Decode** — Verifier calls `instance.decode(hashId, requestId)` to get numeric `codeId`, or `null` if invalid/expired. Verifier must use the same `hashId` received from the client.
51
+
6.**Verify** — User enters the code (or it’s shown). Verifier calls `instance.verify(requestId, secret)`; returns `true` when not expired and code matches.
|[`instance.request(hashId, expireTime?)`](#instancerequesthashid-expiretime)| instance |`RequestId`| Encoded payload string or `''` if hashId invalid. |
57
60
|[`instance.decode(hashId, requestId)`](#instancedecodehashid-requestid)| instance |`CodeId \| null`| Numeric code when valid and not expired. |
58
61
|[`instance.verify(requestId, secret)`](#instanceverifyrequestid-secret)| instance |`boolean`| True when not expired and secret matches code. |
59
62
60
63
## ConnectorId and HashId
61
64
62
65
-**ConnectorId** — Any non-secret string that identifies the connector (e.g. `trustless://auth/example.com:0.1.0?service=none`). Trimmed before hashing. Same value on both sides yields the same encryption key.
63
-
-**HashId** — 197 lowercase hex chars from `Trustless.getHash(connectorId)`. Includes timestamp and random nonce; different on every call. Must be passed to `request` and (on verifier side) to `decode` for the same session.
66
+
-**HashId** — 197 lowercase hex chars from `trustless.generate(connectorId)`. Includes timestamp and random nonce; different on every call. Client must pass `hashId` together with `requestId` to the verifier so the verifier can call `decode(hashId, requestId)`.
-**request(hashId, expireTime?)** — Validates `hashId` (197 hex chars), then encodes `hashId` + current time slot + window. Returns fixed-length `RequestId` or `''` if `hashId` invalid.
73
76
-**expireTime** — Window in seconds (1–60). Default 10. Clamped via `Cipher.clampWindow`. Same `hashId` and same window in the same time slot yields the same `requestId` and same `codeId`.
-**decode(hashId, requestId)** — Decodes with instance key; checks expiry; ensures payload `hashId` matches argument; returns derived numeric code or `null`. Code is in range `0`–`1e10`.
84
87
-**verify(requestId, secret)** — Decodes, checks expiry, derives expected code, compares to `secret`. `secret` can be number or string (digits only); returns `true` when match and not expired.
- Returns: New instance (use for `request`, `decode`, `verify`).
102
105
103
-
### Trustless.getHash(connectorId)
106
+
### trustless.generate(connectorId)
104
107
105
108
Generate a one-time 197-char hex hash. Uses connectorId + timestamp + random nonce. Call once per session; each call returns a different value.
106
109
@@ -111,7 +114,7 @@ Generate a one-time 197-char hex hash. Uses connectorId + timestamp + random non
111
114
112
115
Build the encoded request payload for the given hash and optional expiry window.
113
116
114
-
-`hashId``<HashId>`: 197-char hex from `getHash`.
117
+
-`hashId``<HashId>`: 197-char hex from `generate`.
115
118
-`expireTime``<ExpireTime | undefined>`: Window in seconds (1–60). Default 10.
116
119
- Returns: `<RequestId>` Encoded string of length 205, or `''` if `hashId` invalid.
117
120
@@ -136,7 +139,7 @@ Check that the user-provided secret matches the derived code and the payload is
136
139
Types are exported for TypeScript: `import type { CodeId, ConnectorId, DecodedPayload, ExpireTime, HashId, RequestId, VerifySecret } from '@neabyte/trustless-id'`.
137
140
138
141
-**ConnectorId:**`<string>` — Caller identifier.
139
-
-**HashId:**`<string>` — 197-char hex from `getHash`.
142
+
-**HashId:**`<string>` — 197-char hex from `generate`.
140
143
-**RequestId:**`<string>` — Encoded payload from `request`.
141
144
-**CodeId:**`<number>` — Numeric code from `decode` (0–1e10).
142
145
-**ExpireTime:**`<number>` — Window in seconds (1–60).
0 commit comments