@terminal3/t3n-sdk 1.3.1 → 1.3.2
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 +122 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/src/client/t3n-client.d.ts +34 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -560,6 +560,128 @@ When upserting a profile with an email address (either for a new profile or when
|
|
|
560
560
|
3. Guide you through the Google OAuth flow
|
|
561
561
|
4. Allow you to paste the ID token back into the terminal
|
|
562
562
|
|
|
563
|
+
#### KYC Walkthrough (MAT-1371)
|
|
564
|
+
|
|
565
|
+
The `--kyc-walkthrough` mode drives the full MetaMask KYC L1 + L2 flow against a running Trinity node, end-to-end, without needing the actual MetaMask front-end. It is useful for:
|
|
566
|
+
|
|
567
|
+
- Smoke-testing a freshly-built node (`node/bin/start-local`) before pointing the real FE at it.
|
|
568
|
+
- Reproducing edge cases (rejected KYC, OTP expiry, merge suggestions) deterministically.
|
|
569
|
+
- Showing internal stakeholders what the L1 + L2 flow looks like without spinning up MetaMask Snap + Veriff sandbox.
|
|
570
|
+
|
|
571
|
+
**Quick start (interactive):**
|
|
572
|
+
|
|
573
|
+
```bash
|
|
574
|
+
pnpm demo:real-wasm --kyc-walkthrough
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
The walkthrough then prompts at each step in the order Trinity expects:
|
|
578
|
+
|
|
579
|
+
1. **Handshake** + **authenticate** (existing prompts — wallet / OIDC).
|
|
580
|
+
2. **Email OTP** — request + verify on `tee:user/contracts::user-upsert` (email channel).
|
|
581
|
+
3. **Phone OTP** — request + verify on the same function (SMS channel via `keys.generic_api.otp_channel: "sms"` shadow). Gated by the contract on a verified email.
|
|
582
|
+
4. **Level 1 user-input** — single `user-upsert` call carrying `first_name`, `last_name`, `country_of_residence`, `document_issuance_country`, `ssn`, `address`.
|
|
583
|
+
5. **`create-kyc-provider-session`** ([MAT-1284](https://linear.app/terminal3/issue/MAT-1284)) — prints the Veriff `session_url`. The CLI does **not** auto-open the URL.
|
|
584
|
+
6. **`kyc-status` poll** — until terminal status (`verified`, `rejected`, or `orphan`) or the timeout fires. Each snapshot is logged.
|
|
585
|
+
|
|
586
|
+
**Veriff is driven manually.** The CLI prints the `session_url` and waits — open it in your browser, drive the Veriff flow to the desired terminal state (approve / reject / abandon), then come back to the terminal. The poll loop will see the contract update and surface the terminal status.
|
|
587
|
+
|
|
588
|
+
##### KYC walkthrough flags
|
|
589
|
+
|
|
590
|
+
| Flag | Default | Meaning |
|
|
591
|
+
|---|---|---|
|
|
592
|
+
| `--kyc-walkthrough` | off | Enable the walkthrough mode. Implicitly enabled by `--scenario`. |
|
|
593
|
+
| `--scenario <name>` | none | One of `happy-path-l1`, `happy-path-l2`, `rejected`. See *Scenarios* below. |
|
|
594
|
+
| `--auth-method <eth\|metamask\|oidc>` | interactive prompt | Skip the auth-method prompt. |
|
|
595
|
+
| `--email <addr>` | interactive prompt (or `demo+kyc@example.com` in scenario mode) | Email to verify in the L1 OTP step. |
|
|
596
|
+
| `--phone <e164>` | interactive prompt (or `+14155552671` in scenario mode) | Phone in E.164 format for the SMS OTP step. |
|
|
597
|
+
| `--first-name <name>` | interactive prompt (or `Ada` in scenario mode) | L1 first name. |
|
|
598
|
+
| `--last-name <name>` | interactive prompt (or `Lovelace` in scenario mode) | L1 last name. |
|
|
599
|
+
| `--country <ISO-2>` | `US` | Convenience: applies to both `country_of_residence` and `document_issuance_country` unless overridden individually. |
|
|
600
|
+
| `--country-of-residence <ISO-2>` | `--country` value | L1 residence country. |
|
|
601
|
+
| `--document-issuance-country <ISO-2>` | `--country` value | L1 document issuance country. |
|
|
602
|
+
| `--ssn <value>` | interactive prompt (or `123-45-6789` in scenario mode) | L1 SSN (9 digits or `XXX-XX-XXXX`). |
|
|
603
|
+
| `--address <text>` | interactive prompt (or default address in scenario mode) | L1 residential address. |
|
|
604
|
+
| `--kyc-provider-id <id>` | `veriff` | Provider id passed to `create-kyc-provider-session` and `kyc-status`. |
|
|
605
|
+
| `--kyc-poll-fast-ms <ms>` | `2000` | Fast-cadence poll interval (T3-TS-026 §8.4). |
|
|
606
|
+
| `--kyc-poll-slow-ms <ms>` | `5000` | Slow-cadence poll interval. |
|
|
607
|
+
| `--kyc-poll-switch-at-ms <ms>` | `30000` | Elapsed threshold to switch from fast to slow. |
|
|
608
|
+
| `--kyc-poll-timeout-ms <ms>` | `300000` | Total cap before `KycStatusTimeoutError` is raised. |
|
|
609
|
+
| `--skip-create-kyc-session` | off | Stop after L1 — useful when no Veriff sandbox is configured. |
|
|
610
|
+
|
|
611
|
+
##### Scenarios
|
|
612
|
+
|
|
613
|
+
Pre-baked shortcuts that auto-feed answers (mock-mode OTP codes, default L1 fields) so the walkthrough runs without operator input. All scenarios still require a running Trinity node configured with the **mock OTP provider** (otherwise the deterministic OTP code algorithm doesn't match what the node actually generated).
|
|
614
|
+
|
|
615
|
+
| Scenario | What it does | Veriff |
|
|
616
|
+
|---|---|---|
|
|
617
|
+
| `happy-path-l1` | Email OTP → phone OTP → L1 upsert. Stops before `create-kyc-provider-session`. | Not exercised. |
|
|
618
|
+
| `happy-path-l2` | Full L1 + L2 flow. Asserts `kyc-status` terminates with `verified`. | **Manual**: open the printed `session_url` and drive Veriff to approval. |
|
|
619
|
+
| `rejected` | Full L1 + L2 flow. Asserts `kyc-status` terminates with `rejected`. | **Manual**: open the printed `session_url` and drive Veriff to a rejection. |
|
|
620
|
+
|
|
621
|
+
Examples:
|
|
622
|
+
|
|
623
|
+
```bash
|
|
624
|
+
# L1-only happy path — no Veriff sandbox needed
|
|
625
|
+
pnpm demo:real-wasm --scenario happy-path-l1
|
|
626
|
+
|
|
627
|
+
# Full L1 + L2 happy path — drive Veriff to approved manually
|
|
628
|
+
pnpm demo:real-wasm --scenario happy-path-l2
|
|
629
|
+
|
|
630
|
+
# Rejection scenario — drive Veriff to a rejection manually
|
|
631
|
+
pnpm demo:real-wasm --scenario rejected
|
|
632
|
+
|
|
633
|
+
# Custom inputs without a scenario
|
|
634
|
+
pnpm demo:real-wasm --kyc-walkthrough \
|
|
635
|
+
--auth-method eth \
|
|
636
|
+
--email me@example.com \
|
|
637
|
+
--phone +14155551234 \
|
|
638
|
+
--country US \
|
|
639
|
+
--first-name Ada --last-name Lovelace
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
##### Mock-mode OTP code
|
|
643
|
+
|
|
644
|
+
When the Trinity node runs against the mock OTP provider (the default for `node/bin/start-local`), the OTP code is a **deterministic** 6-digit hash of the contact value. The walkthrough always prints the calculated mock code in the OTP-pending log line, so even without a scenario you can simply enter that code at the prompt to advance.
|
|
645
|
+
|
|
646
|
+
The algorithm matches `node/wasm/src/otp.rs` byte-for-byte: `String((hash * 31 + byte_i) % 1_000_000).padStart(6, "0")` over the UTF-8 bytes of the contact (email address or E.164 phone).
|
|
647
|
+
|
|
648
|
+
##### Sample output (excerpt)
|
|
649
|
+
|
|
650
|
+
```text
|
|
651
|
+
🚦 KYC walkthrough mode enabled (MAT-1371)
|
|
652
|
+
Scenario: happy-path-l1
|
|
653
|
+
|
|
654
|
+
📧 Step 5/8 — Email OTP: demo+kyc@example.com
|
|
655
|
+
5️⃣ Executing action: user-upsert...
|
|
656
|
+
✅ Action executed successfully
|
|
657
|
+
📨 Email verification required
|
|
658
|
+
📬 OTP code sent to: demo+kyc@example.com
|
|
659
|
+
📡 Channel: email
|
|
660
|
+
💡 Mock mode OTP code (deterministic): 482913
|
|
661
|
+
🤖 Scenario auto-feeding OTP code: 482913
|
|
662
|
+
🔄 Verifying Email OTP code...
|
|
663
|
+
5️⃣ Executing action: user-upsert...
|
|
664
|
+
✅ OTP verified successfully
|
|
665
|
+
📝 Transaction hash: tx:1:42
|
|
666
|
+
|
|
667
|
+
📱 Step 6/8 — Phone OTP: +14155552671
|
|
668
|
+
6️⃣ Executing action: user-upsert...
|
|
669
|
+
...
|
|
670
|
+
|
|
671
|
+
📋 KYC walkthrough summary
|
|
672
|
+
✅ email-otp demo+kyc@example.com
|
|
673
|
+
✅ phone-otp +14155552671
|
|
674
|
+
✅ l1-upsert tx:1:44
|
|
675
|
+
⏭️ create-kyc-session (scenario)
|
|
676
|
+
⏭️ kyc-status-poll (scenario)
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
##### Caveats
|
|
680
|
+
|
|
681
|
+
- **No version bump.** The walkthrough is dev tooling — it does not introduce new `@terminal3/t3n-sdk` public-API surface, so `package.json` is not bumped.
|
|
682
|
+
- **Spec alignment.** The walkthrough follows the as-built code, which differs from earlier T3-TS-026 versions on two points: `user-upsert` has no `op:` discriminator (dispatch is implicit on input shape), and the function for L2 session creation is `tee:user/contracts::create-kyc-provider-session` rather than `tee:kyc/contracts::create-session`. See [T3-TS-026 v0.6.0 changelog](../../docs/specs/T3-TS-026-kyc-frontend-integration.md) and [MAT-1374](https://linear.app/terminal3/issue/MAT-1374) for the deferred discriminator-vs-split decision.
|
|
683
|
+
- **`STRICT_SCENARIO=true`** in the environment turns scenario assertion failures into a non-zero exit code (otherwise they're logged but the demo exits zero). `--scenario` always exits non-zero on a terminal-status mismatch.
|
|
684
|
+
|
|
563
685
|
## WASM Integration
|
|
564
686
|
|
|
565
687
|
The SDK can work with both real T3n WASM components and mock components for testing.
|
package/dist/index.d.ts
CHANGED
|
@@ -804,6 +804,14 @@ declare class KycStatusTimeoutError extends T3nError {
|
|
|
804
804
|
declare class T3nClient {
|
|
805
805
|
private readonly config;
|
|
806
806
|
private readonly transport;
|
|
807
|
+
/**
|
|
808
|
+
* Resolved node base URL. Snapshotted in the constructor so the
|
|
809
|
+
* typed contract wrappers (`kycStatus`, `getSelfEthAddress`, …)
|
|
810
|
+
* can call `getScriptVersion()` against the same host the
|
|
811
|
+
* transport talks to. Used only by the `script_version: "latest"`
|
|
812
|
+
* resolution path in {@link executeUserContract}.
|
|
813
|
+
*/
|
|
814
|
+
private readonly effectiveBaseUrl;
|
|
807
815
|
/**
|
|
808
816
|
* Server-minted session ID, set by {@link handshake} from the
|
|
809
817
|
* `Session-Id` response header (pentest M-1 / MAT-983). `null`
|
|
@@ -899,6 +907,32 @@ declare class T3nClient {
|
|
|
899
907
|
* @throws {ContractResponseError} when the response is not valid JSON
|
|
900
908
|
*/
|
|
901
909
|
executeAndDecode<T = unknown>(payload: unknown, schema?: ContractResponseSchema<T>): Promise<T>;
|
|
910
|
+
/**
|
|
911
|
+
* Build the canonical `ExecuteActionRequest` shape the server
|
|
912
|
+
* expects in `node/primitives/src/action.rs::ExecuteActionRequest`
|
|
913
|
+
* (`script_name`, `script_version`, `function_name`, `input`,
|
|
914
|
+
* optional `pii_did`) and dispatch it through {@link execute}.
|
|
915
|
+
*
|
|
916
|
+
* Two pieces of glue live here that every typed user-contract
|
|
917
|
+
* wrapper would otherwise duplicate:
|
|
918
|
+
*
|
|
919
|
+
* 1. **Field naming.** The server deserialises strictly into
|
|
920
|
+
* `script_name` / `script_version` / `function_name` —
|
|
921
|
+
* sending `contract` / `version` / `function` produces
|
|
922
|
+
* `Invalid action request: missing field …` 400s. Centralising
|
|
923
|
+
* the names here means every wrapper agrees with the server.
|
|
924
|
+
* 2. **`"latest"` resolution.** `script_version` is `SemVer` on
|
|
925
|
+
* the server, so a literal `"latest"` cannot be parsed. We
|
|
926
|
+
* fetch the registered current version via
|
|
927
|
+
* `GET /api/contracts/current?name=…` (cached per script name
|
|
928
|
+
* in `getScriptVersion`) and forward the resolved
|
|
929
|
+
* `MAJOR.MINOR.PATCH` string.
|
|
930
|
+
*
|
|
931
|
+
* Wrappers that need PII delegation can extend this helper
|
|
932
|
+
* later — current call sites are all SelfOnly so `pii_did` stays
|
|
933
|
+
* implicit.
|
|
934
|
+
*/
|
|
935
|
+
private executeUserContract;
|
|
902
936
|
/**
|
|
903
937
|
* Return the authenticated user's Ethereum address from their
|
|
904
938
|
* T3N-hosted per-user wallet, as a 0x-prefixed lowercase hex string.
|