@shadowbreaker/sdk 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +81 -20
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,18 +1,32 @@
1
- # ShadowBreaker SDK
1
+ <p align="center"><img src="https://shadowbreaker-bnb-web.vercel.app/brand.png" width="80" alt="ShadowBreaker shield"></p>
2
2
 
3
- Verify security advisories directly against a BNB Smart Chain testnet registry. The reader queries two RPC providers, compares their shared finalized block and advisory tuple, and returns the result with its verification evidence.
3
+ # @shadowbreaker/sdk 0.1.1
4
4
 
5
- ## Install
5
+ The BNB Smart Chain testnet advisory reader, hostname key helpers, and verification types for ShadowBreaker. Your app can check whether a maintainer has warned users away from a dApp before asking them to connect a wallet, even if the dApp site is down.
6
+
7
+ [ShadowBreaker](https://shadowbreaker-bnb-web.vercel.app) · [Command-line reader](https://www.npmjs.com/package/@shadowbreaker/cli) · [Protocol specification](./PROTOCOL.md)
6
8
 
7
- After the npm release, install the SDK by version.
9
+ ## Install
8
10
 
9
11
  ```sh
10
- npm install @shadowbreaker/sdk@0.1.0
12
+ npm install --save-exact @shadowbreaker/sdk@0.1.1
11
13
  ```
12
14
 
13
- Use Node.js 22 or newer. The package ships ESM and TypeScript declarations. In the protocol repository, `npm ci` and `npm run build` build the local SDK and CLI together.
15
+ Requires Node.js 22 or newer. The package ships ESM and TypeScript declarations. For terminal use, install the [ShadowBreaker CLI](https://www.npmjs.com/package/@shadowbreaker/cli).
16
+
17
+ ## BSC testnet configuration
18
+
19
+ Set `BSC_REGISTRY_ADDRESS` to the trusted deployment address and configure two independently operated HTTPS endpoints in `BSC_RPC_URL_PRIMARY` and `BSC_RPC_URL_SECONDARY`. Both must support the finalized block tag and EIP-1898 canonical block-hash reads on BSC testnet, chain ID `97`. The SDK takes the registry address from your configuration. The registry contract enforces publisher authorization, and the SDK verifies reads through the configured RPC pair. [Testnet RPC documentation](https://docs.bnbchain.org/bnb-smart-chain/developers/json_rpc/json-rpc-endpoint/#bsc-testnet-chainid-0x61-97-in-decimal)
14
20
 
15
- ## Read an advisory
21
+ ```mermaid
22
+ flowchart LR
23
+ Registry["Trusted testnet registry address"] --> Config["createRegistry"]
24
+ Primary["Primary HTTPS endpoint"] --> Config
25
+ Secondary["Secondary HTTPS endpoint"] --> Config
26
+ Config --> Reader["Configured registry reader"]
27
+ ```
28
+
29
+ ## Read one hostname
16
30
 
17
31
  ```ts
18
32
  import { createRegistry, readAdvisory } from "@shadowbreaker/sdk";
@@ -25,24 +39,71 @@ const registry = createRegistry({
25
39
  ],
26
40
  });
27
41
 
28
- const result = await readAdvisory("swap.example.org", registry);
29
- console.log(result.state, result.reason, result.chain);
42
+ if (!registry) {
43
+ throw new Error("Configure the registry and two distinct HTTPS RPC endpoints.");
44
+ }
45
+
46
+ const status = await readAdvisory("swap.example.org", registry);
47
+
48
+ console.log({
49
+ state: status.state,
50
+ reason: status.reason,
51
+ revision: status.advisory?.revision,
52
+ blockHash: status.chain?.blockHash,
53
+ });
30
54
  ```
31
55
 
32
- Use the expected registry contract address and two independently operated HTTPS RPCs with distinct hostnames. Both must support the `finalized` block tag and canonical hash-scoped `eth_call` on chain ID 97. The reader rejects HTTP redirects and handles registry calls entirely through the configured RPC pair. An invalid configuration returns `null` from `createRegistry`.
56
+ This read requires no wallet and submits no transaction. Pass an ASCII DNS hostname such as `swap.example.org`. URLs, paths, ports, and IP addresses are rejected. Hostnames are lowercased and one trailing dot is removed. Internationalized names must use their ASCII Punycode form. Each subdomain has its own record.
33
57
 
34
- `readAdvisory` takes an exact ASCII DNS hostname. It lowercases the hostname and removes a single trailing dot. Pass internationalized labels in their ASCII Punycode form. URLs, ports, IP addresses, and invalid hostnames throw `TypeError`. The exported `normalizeHostname` returns `null` on invalid input, and `hostnameKey` returns the Keccak-256 registry key from the normalized hostname.
58
+ ## From hostname to evidence
59
+
60
+ Two providers must agree on the same fresh finalized block and on the registry record read at that block hash. The SDK then checks publication state and returns the corresponding result.
61
+
62
+ ```mermaid
63
+ flowchart LR
64
+ Host["Exact hostname"] --> Key["Normalize and hash"]
65
+ Key --> RPC["Two HTTPS RPC providers"]
66
+ RPC --> Block{"Same fresh finalized block?"}
67
+ Block -->|Yes| Record{"Same canonical registry record?"}
68
+ Record -->|Yes| State["Evaluate advisory and evidence"]
69
+ Block -->|No| Unknown["Status unconfirmed"]
70
+ Record -->|No| Unknown
71
+ ```
72
+
73
+ | Result | Meaning |
74
+ | --- | --- |
75
+ | `active` | The enrolled publisher has an active warning. Show it and advise users to keep their wallet disconnected. |
76
+ | `cleared` | The registry has an authorized clearance for a previous warning. |
77
+ | `unconfirmed` | The read failed verification, the warning expired, or the publisher is suspended. Keep any previously verified warning visible until a newer clearance is verified. |
78
+ | `no_advisory` | The hostname is enrolled and its registry record has no advisory. |
79
+ | `not_enrolled` | The checked registry has no enrollment for this hostname. |
80
+
81
+ A verified read supplies the registry address, chain ID, finalized block number, block hash, and block timestamp in `chain`. A warning or clearance supplies its revision and evidence digest in `advisory`. Block numbers and revisions are decimal strings. Timestamps are UTC ISO 8601 strings.
82
+
83
+ An expired or suspended warning can still carry verified record evidence. A failed chain verification returns no new chain evidence. For a client that persists warnings, key them by chain, registry, and hostname. Clear a cached warning only after verifying a higher-revision clearance from the same registry. The result describes a maintainer advisory. Keep the user's normal wallet and transaction checks in the flow.
84
+
85
+ ```mermaid
86
+ stateDiagram-v2
87
+ state "Verified warning" as Warning
88
+ state "Last warning retained" as Retained
89
+ state "Verified clearance" as Cleared
90
+ [*] --> Warning: Active warning verified
91
+ Warning --> Retained: Expired, suspended, or unavailable
92
+ Retained --> Warning: Active warning verified
93
+ Warning --> Cleared: Higher-revision clearance verified
94
+ Retained --> Cleared: Higher-revision clearance verified
95
+ ```
35
96
 
36
- ## Interpret the result
97
+ ## Public API
37
98
 
38
- | State | Meaning |
99
+ | Export | Use |
39
100
  | --- | --- |
40
- | `not_enrolled` | The registry contains no publisher for the hostname |
41
- | `no_advisory` | The publisher is enrolled and has never posted an advisory |
42
- | `active` | A current warning from the enrolled publisher was verified |
43
- | `cleared` | An authorized clearance was verified |
44
- | `unconfirmed` | Data could not be verified, the warning expired, or the publisher is suspended |
101
+ | `createRegistry(options)` | Configure a trusted registry and RPC pair. Returns `null` for invalid configuration. |
102
+ | `readAdvisory(hostname, registry)` | Resolve a typed `AdvisoryStatus`. Invalid hostname input throws `TypeError`. |
103
+ | `normalizeHostname(input)` | Return the normalized hostname or `null`. |
104
+ | `hostnameKey(input)` | Return the registry key as the Keccak-256 hash of the normalized hostname. |
105
+ | `advisoryStates`, `isAdvisoryState(value)` | Enumerate and narrow the possible status values. |
45
106
 
46
- A verified result includes `chain.blockNumber`, `chain.blockHash`, `chain.blockTimestamp`, and the contract address. Unconfirmed responses include chain evidence and the warning when both providers can verify the record's expiry or suspension. Preserve a previous verified warning when a later read loses verification. Resolve it after verifying a newer clearance from the same registry.
107
+ The package includes `PROTOCOL.md` with the registry ABI, a hostname hash vector, and the precise verification rules. The client trusts the registry address you supply. Distinct endpoint hostnames are required, and provider independence should be verified separately.
47
108
 
48
- The SDK is stateless and reads the testnet registry without a wallet. The result describes the advisory status of the enrolled hostname. The npm package includes the [protocol specification](./PROTOCOL.md), which defines the record format and verification rules.
109
+ MIT licensed.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shadowbreaker/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Verify ShadowBreaker advisories directly against two BNB Smart Chain testnet RPC providers.",
5
5
  "type": "module",
6
6
  "license": "MIT",