@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.
- package/README.md +81 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,18 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center"><img src="https://shadowbreaker-bnb-web.vercel.app/brand.png" width="80" alt="ShadowBreaker shield"></p>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# @shadowbreaker/sdk 0.1.1
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
|
|
9
|
+
## Install
|
|
8
10
|
|
|
9
11
|
```sh
|
|
10
|
-
npm install @shadowbreaker/sdk@0.1.
|
|
12
|
+
npm install --save-exact @shadowbreaker/sdk@0.1.1
|
|
11
13
|
```
|
|
12
14
|
|
|
13
|
-
|
|
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
|
-
|
|
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
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
97
|
+
## Public API
|
|
37
98
|
|
|
38
|
-
|
|
|
99
|
+
| Export | Use |
|
|
39
100
|
| --- | --- |
|
|
40
|
-
| `
|
|
41
|
-
| `
|
|
42
|
-
| `
|
|
43
|
-
| `
|
|
44
|
-
| `
|
|
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
|
-
|
|
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
|
-
|
|
109
|
+
MIT licensed.
|