@shadowbreaker/sdk 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ShadowBreaker contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/PROTOCOL.md ADDED
@@ -0,0 +1,69 @@
1
+ # ShadowBreaker protocol v0.1
2
+
3
+ An independent reader can reproduce an exact-host advisory from the same finalized BNB Smart Chain testnet record. This prototype uses chain ID `97` and a trusted registry address supplied by the operator. A public registry address and live testnet evidence are pending. An advisory state does not certify that a website is safe.
4
+
5
+ ## Host key
6
+
7
+ Accept one ASCII DNS hostname. Lowercase it and remove one optional final dot. The result must contain at least two labels and at most 253 characters. Each label is 1–63 characters of lowercase letters, digits, or hyphens, and cannot begin or end with a hyphen. The last label starts with an ASCII letter. URLs, paths, ports, whitespace, and Unicode input are invalid. An IDN can be provided in its ASCII form. Each subdomain has its own record.
8
+
9
+ Use Ethereum Keccak-256 over the UTF-8 bytes of the normalized hostname. The following fixture was checked with `cast keccak 'swap.shadowbreaker.example'`.
10
+
11
+ | Input | Value |
12
+ | --- | --- |
13
+ | Original hostname | `SWAP.ShadowBreaker.Example.` |
14
+ | Normalized hostname | `swap.shadowbreaker.example` |
15
+ | Host key | `0xfe29cd7e897ab1163f114d5ca03807417ffe7a4069483ec1ec6b37406ec0ec77` |
16
+
17
+ ## Registry record
18
+
19
+ Call the following function on the configured `AdvisoryRegistry`.
20
+
21
+ ```solidity
22
+ function read(bytes32 hostKey) external view returns (
23
+ address publisher, bool suspended, uint8 kind, uint64 revision,
24
+ uint64 issuedAt, uint64 expiresAt, bytes32 evidenceDigest
25
+ );
26
+ ```
27
+
28
+ The enrollment admin assigns the publisher once and can suspend it. Only the enrolled, unsuspended publisher can publish or clear at the exact current revision. Each accepted write advances the revision by one and sets the issue time to the write block's Unix timestamp in seconds.
29
+
30
+ | Kind | Record rules |
31
+ | --- | --- |
32
+ | `0` None | Revision, issue time, expiry, and digest are zero. A zero publisher marks an unenrolled host, which cannot be suspended. |
33
+ | `1` Warning | Revision is at least 1. Expiry follows issue time by at most seven days. Warning publications for the same host are at least 60 seconds apart. |
34
+ | `2` Clearance | Replaces an existing warning, even after expiry. Revision is at least 2 and expiry is zero. |
35
+
36
+ Warnings and clearances have nonzero publishers and evidence digests. Their issue times are positive and at or before the selected block timestamp. The digest commits to reviewed evidence. It is an opaque value for readers. Expiry and suspension leave the stored record intact.
37
+
38
+ ## Independent verification
39
+
40
+ 1. Configure two independently operated HTTPS RPC endpoints with distinct hostnames after lowercasing and removing an optional final dot. Both must return chain ID `97` from `eth_chainId`. Redirected RPC requests fail verification.
41
+ 2. Fetch each endpoint's `finalized` block. Use the lower finalized block number and fetch that height from the endpoint with the later head. Both endpoints must agree on the selected block's number, hash, and timestamp.
42
+ 3. Call `read(hostKey)` on both endpoints at the same block hash, using `{ "blockHash": "<hash>", "requireCanonical": true }` as the block argument for `eth_call`. Require identical, consistent records. [EIP-1898](https://eips.ethereum.org/EIPS/eip-1898)
43
+ 4. At the time of verification, reject a block timestamp more than 90 seconds old or more than 15 seconds in the future. Missing or invalid RPC data, unsupported methods, disagreements, and stale blocks produce `unconfirmed` with no verified chain evidence.
44
+
45
+ | Status | Meaning |
46
+ | --- | --- |
47
+ | `not_enrolled` | Verified empty record with zero publisher. |
48
+ | `no_advisory` | Verified enrolled and unsuspended host with an empty record. |
49
+ | `active` | Verified unsuspended warning whose expiry is after the time of verification. |
50
+ | `cleared` | Verified clearance from an unsuspended publisher. |
51
+ | `unconfirmed` | Verification failed, the publisher is suspended, or the warning expired. A verified expired or suspended warning may still be returned with its evidence. |
52
+
53
+ JSON results include the normalized `hostname`, `state`, `checkedAt`, `reason`, `publisher`, and any `advisory` and `chain` evidence. Revisions and block numbers are decimal strings. Timestamps are UTC ISO 8601 strings. An advisory's `reference` is the hex evidence digest. Verified chain evidence includes `id`, `contractAddress`, `blockNumber`, `blockHash`, and `blockTimestamp`.
54
+
55
+ Clients that persist warnings should key them by chain, registry, and normalized hostname. Keep the last verified warning visible as unconfirmed when a fresh read cannot verify it. A subsequent verified clearance must come from the same registry at a higher revision. Reject a lower block or revision and conflicting evidence for a block or revision already verified.
56
+
57
+ ## Local reader
58
+
59
+ The v0.1 workspace packages are `@shadowbreaker/sdk` and `@shadowbreaker/cli`. Run these commands from the root of the `shadowbraker-v2/protocol` repository. Configure the CLI with `BSC_REGISTRY_ADDRESS`, `BSC_RPC_URL_PRIMARY`, and `BSC_RPC_URL_SECONDARY`, or supply the settings as shown.
60
+
61
+ ```sh
62
+ npm ci
63
+ npm run build
64
+ node packages/cli/dist/cli.js check swap.shadowbreaker.example \
65
+ --registry "$BSC_REGISTRY_ADDRESS" \
66
+ --rpc "$BSC_RPC_URL_PRIMARY" --rpc "$BSC_RPC_URL_SECONDARY" --json
67
+ ```
68
+
69
+ The exit code is `0` for a verified state, including an active warning, `2` for an unconfirmed state, and `1` for invalid usage or configuration. Inspect `state` to decide what to display.
package/README.md CHANGED
@@ -1,3 +1,48 @@
1
- # Temporary Holding Version
1
+ # ShadowBreaker SDK
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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.
4
+
5
+ ## Install
6
+
7
+ After the npm release, install the SDK by version.
8
+
9
+ ```sh
10
+ npm install @shadowbreaker/sdk@0.1.0
11
+ ```
12
+
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.
14
+
15
+ ## Read an advisory
16
+
17
+ ```ts
18
+ import { createRegistry, readAdvisory } from "@shadowbreaker/sdk";
19
+
20
+ const registry = createRegistry({
21
+ address: process.env.BSC_REGISTRY_ADDRESS ?? "",
22
+ rpcUrls: [
23
+ process.env.BSC_RPC_URL_PRIMARY ?? "",
24
+ process.env.BSC_RPC_URL_SECONDARY ?? "",
25
+ ],
26
+ });
27
+
28
+ const result = await readAdvisory("swap.example.org", registry);
29
+ console.log(result.state, result.reason, result.chain);
30
+ ```
31
+
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`.
33
+
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.
35
+
36
+ ## Interpret the result
37
+
38
+ | State | Meaning |
39
+ | --- | --- |
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 |
45
+
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.
47
+
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.
@@ -0,0 +1,27 @@
1
+ import type { Hash } from "viem";
2
+ export declare const advisoryStates: readonly ["not_enrolled", "no_advisory", "active", "unconfirmed", "cleared"];
3
+ export type AdvisoryState = (typeof advisoryStates)[number];
4
+ export interface Advisory {
5
+ revision: string;
6
+ issuedAt: string;
7
+ expiresAt: string | null;
8
+ reference: string;
9
+ }
10
+ export interface ChainEvidence {
11
+ id: 97;
12
+ blockNumber: string;
13
+ blockHash: Hash;
14
+ blockTimestamp: string;
15
+ contractAddress: string;
16
+ }
17
+ export interface AdvisoryStatus {
18
+ hostname: string;
19
+ state: AdvisoryState;
20
+ checkedAt: string;
21
+ reason: string;
22
+ advisory: Advisory | null;
23
+ chain: ChainEvidence | null;
24
+ publisher: string | null;
25
+ }
26
+ export declare function normalizeHostname(input: string): string | null;
27
+ export declare function isAdvisoryState(value: string): value is AdvisoryState;
@@ -0,0 +1,26 @@
1
+ export const advisoryStates = [
2
+ "not_enrolled",
3
+ "no_advisory",
4
+ "active",
5
+ "unconfirmed",
6
+ "cleared",
7
+ ];
8
+ const dnsLabel = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
9
+ const dnsTopLevelLabel = /^[a-z]/;
10
+ export function normalizeHostname(input) {
11
+ if (typeof input !== "string" || /[^\x00-\x7f]/.test(input))
12
+ return null;
13
+ const hostname = input.toLowerCase().replace(/\.$/, "");
14
+ const labels = hostname.split(".");
15
+ const topLevel = labels.at(-1) ?? "";
16
+ if (hostname.length > 253 ||
17
+ labels.length < 2 ||
18
+ !labels.every((label) => dnsLabel.test(label)) ||
19
+ !dnsTopLevelLabel.test(topLevel)) {
20
+ return null;
21
+ }
22
+ return hostname;
23
+ }
24
+ export function isAdvisoryState(value) {
25
+ return advisoryStates.some((state) => state === value);
26
+ }
@@ -0,0 +1,4 @@
1
+ export { advisoryStates, isAdvisoryState, normalizeHostname } from "./advisory.js";
2
+ export type { Advisory, AdvisoryState, AdvisoryStatus, ChainEvidence } from "./advisory.js";
3
+ export { createRegistry, hostnameKey, readAdvisory } from "./registry.js";
4
+ export type { Registry, RegistryBlock, RegistryOptions, RegistryReader, RegistryRecord, } from "./registry.js";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { advisoryStates, isAdvisoryState, normalizeHostname } from "./advisory.js";
2
+ export { createRegistry, hostnameKey, readAdvisory } from "./registry.js";
@@ -0,0 +1,33 @@
1
+ import type { Address, Hash } from "viem";
2
+ import type { AdvisoryStatus } from "./advisory.js";
3
+ export type RegistryRecord = readonly [
4
+ publisher: Address,
5
+ suspended: boolean,
6
+ kind: number,
7
+ revision: bigint,
8
+ issuedAt: bigint,
9
+ expiresAt: bigint,
10
+ evidenceDigest: Hash
11
+ ];
12
+ export interface RegistryBlock {
13
+ number: bigint | null;
14
+ hash: Hash | null;
15
+ timestamp: bigint;
16
+ }
17
+ export interface RegistryReader {
18
+ getChainId(): Promise<number>;
19
+ getFinalizedBlock(): Promise<RegistryBlock>;
20
+ getBlock(number: bigint): Promise<RegistryBlock>;
21
+ read(hostKey: Hash, blockHash: Hash): Promise<RegistryRecord>;
22
+ }
23
+ export interface Registry {
24
+ readonly address: Address;
25
+ readonly providers: readonly [RegistryReader, RegistryReader];
26
+ }
27
+ export interface RegistryOptions {
28
+ readonly address: string;
29
+ readonly rpcUrls: readonly [string, string];
30
+ }
31
+ export declare function createRegistry(options: RegistryOptions): Registry | null;
32
+ export declare function hostnameKey(input: string): Hash;
33
+ export declare function readAdvisory(input: string, registry: Registry | null, clock?: () => Date): Promise<AdvisoryStatus>;
@@ -0,0 +1,268 @@
1
+ import { createPublicClient, http, isAddress, keccak256, parseAbi, stringToHex, zeroAddress, } from "viem";
2
+ import { bscTestnet } from "viem/chains";
3
+ import { normalizeHostname } from "./advisory.js";
4
+ const chainId = 97;
5
+ const maxFinalizedAgeSeconds = 90n;
6
+ const maxFutureSkewSeconds = 15n;
7
+ const maxWarningDurationSeconds = 7n * 24n * 60n * 60n;
8
+ const maxDateSeconds = 8640000000000n;
9
+ const maxUint64 = (1n << 64n) - 1n;
10
+ const zeroDigest = `0x${"0".repeat(64)}`;
11
+ const digestPattern = /^0x[0-9a-f]{64}$/i;
12
+ const registryAbi = parseAbi([
13
+ "function read(bytes32 hostKey) view returns (address publisher, bool suspended, uint8 kind, uint64 revision, uint64 issuedAt, uint64 expiresAt, bytes32 evidenceDigest)",
14
+ ]);
15
+ function rpcUrl(raw) {
16
+ if (typeof raw !== "string" || !raw)
17
+ return null;
18
+ try {
19
+ const url = new URL(raw);
20
+ return url.protocol === "https:" && !url.username && !url.password && !url.hash
21
+ ? url
22
+ : null;
23
+ }
24
+ catch {
25
+ return null;
26
+ }
27
+ }
28
+ function makeReader(url, address) {
29
+ const clients = createPublicClient({
30
+ chain: bscTestnet,
31
+ cacheTime: 0,
32
+ ccipRead: false,
33
+ transport: http(url.href, {
34
+ retryCount: 0,
35
+ timeout: 3_000,
36
+ fetchOptions: { redirect: "error" },
37
+ }),
38
+ });
39
+ return {
40
+ getChainId: () => clients.getChainId(),
41
+ getFinalizedBlock: () => clients.getBlock({ blockTag: "finalized" }),
42
+ getBlock: (blockNumber) => clients.getBlock({ blockNumber }),
43
+ read: (hostKey, blockHash) => clients.readContract({
44
+ address,
45
+ abi: registryAbi,
46
+ functionName: "read",
47
+ args: [hostKey],
48
+ blockHash,
49
+ requireCanonical: true,
50
+ }),
51
+ };
52
+ }
53
+ export function createRegistry(options) {
54
+ const primary = rpcUrl(options?.rpcUrls?.[0]);
55
+ const secondary = rpcUrl(options?.rpcUrls?.[1]);
56
+ const primaryHostname = primary?.hostname.toLowerCase().replace(/\.$/, "");
57
+ const secondaryHostname = secondary?.hostname.toLowerCase().replace(/\.$/, "");
58
+ const address = typeof options?.address === "string" ? options.address.trim() : "";
59
+ if (!primary ||
60
+ !secondary ||
61
+ primaryHostname === secondaryHostname ||
62
+ !address ||
63
+ !isAddress(address) ||
64
+ address.toLowerCase() === zeroAddress) {
65
+ return null;
66
+ }
67
+ return {
68
+ address,
69
+ providers: [makeReader(primary, address), makeReader(secondary, address)],
70
+ };
71
+ }
72
+ export function hostnameKey(input) {
73
+ const hostname = normalizeHostname(input);
74
+ if (!hostname)
75
+ throw new TypeError("Enter a DNS hostname without a URL or port.");
76
+ return keccak256(stringToHex(hostname));
77
+ }
78
+ function recordEqual(left, right) {
79
+ return (Array.isArray(left) &&
80
+ Array.isArray(right) &&
81
+ left.length === 7 &&
82
+ right.length === 7 &&
83
+ left.every((part, index) => {
84
+ const other = right[index];
85
+ return typeof part === "string" && typeof other === "string"
86
+ ? part.toLowerCase() === other.toLowerCase()
87
+ : part === other;
88
+ }));
89
+ }
90
+ function validBlock(block) {
91
+ return (typeof block.number === "bigint" &&
92
+ block.number >= 0n &&
93
+ typeof block.hash === "string" &&
94
+ digestPattern.test(block.hash) &&
95
+ typeof block.timestamp === "bigint" &&
96
+ block.timestamp > 0n);
97
+ }
98
+ function uint64(value) {
99
+ return typeof value === "bigint" && value >= 0n && value <= maxUint64;
100
+ }
101
+ function isoTimestamp(seconds) {
102
+ return new Date(Number(seconds) * 1_000).toISOString();
103
+ }
104
+ function presentRecord(base, chain, record, blockTime, now) {
105
+ const [publisher, suspended, kind, revision, issuedAt, expiresAt, evidenceDigest] = record;
106
+ const inconsistent = "The registry response did not contain a consistent advisory.";
107
+ if (typeof publisher !== "string" ||
108
+ !isAddress(publisher, { strict: false }) ||
109
+ typeof suspended !== "boolean" ||
110
+ !uint64(revision) ||
111
+ !uint64(issuedAt) ||
112
+ !uint64(expiresAt) ||
113
+ typeof evidenceDigest !== "string" ||
114
+ !digestPattern.test(evidenceDigest)) {
115
+ return { ...base, reason: inconsistent };
116
+ }
117
+ const enrolled = publisher.toLowerCase() !== zeroAddress;
118
+ if (kind === 0 &&
119
+ revision === 0n &&
120
+ issuedAt === 0n &&
121
+ expiresAt === 0n &&
122
+ evidenceDigest === zeroDigest &&
123
+ (enrolled || !suspended)) {
124
+ if (suspended) {
125
+ return {
126
+ ...base,
127
+ chain,
128
+ publisher,
129
+ reason: "The registry suspended the publisher. Status is unconfirmed.",
130
+ };
131
+ }
132
+ return {
133
+ ...base,
134
+ chain,
135
+ publisher: enrolled ? publisher : null,
136
+ state: enrolled ? "no_advisory" : "not_enrolled",
137
+ reason: enrolled
138
+ ? "This hostname is enrolled and has no published advisory."
139
+ : "There is no enrolled publisher for this hostname on the BSC testnet registry.",
140
+ };
141
+ }
142
+ if (!enrolled ||
143
+ (kind !== 1 && kind !== 2) ||
144
+ revision <= 0n ||
145
+ issuedAt <= 0n ||
146
+ issuedAt > blockTime ||
147
+ issuedAt > maxDateSeconds ||
148
+ evidenceDigest === zeroDigest ||
149
+ (kind === 1 &&
150
+ (expiresAt <= issuedAt ||
151
+ expiresAt > issuedAt + maxWarningDurationSeconds ||
152
+ expiresAt > maxDateSeconds)) ||
153
+ (kind === 2 && (revision < 2n || expiresAt !== 0n))) {
154
+ return { ...base, reason: inconsistent };
155
+ }
156
+ const advisory = {
157
+ revision: revision.toString(),
158
+ issuedAt: isoTimestamp(issuedAt),
159
+ expiresAt: expiresAt === 0n ? null : isoTimestamp(expiresAt),
160
+ reference: evidenceDigest,
161
+ };
162
+ if (suspended) {
163
+ return {
164
+ ...base,
165
+ chain,
166
+ publisher,
167
+ advisory: kind === 1 ? advisory : null,
168
+ reason: "The registry suspended the publisher. Keep your wallet disconnected until an authorized clearance is verified.",
169
+ };
170
+ }
171
+ if (kind === 1 && expiresAt <= now) {
172
+ return {
173
+ ...base,
174
+ chain,
175
+ publisher,
176
+ advisory,
177
+ reason: "The last verified warning has expired. Keep your wallet disconnected until an authorized clearance is verified.",
178
+ };
179
+ }
180
+ return {
181
+ ...base,
182
+ chain,
183
+ publisher,
184
+ advisory,
185
+ state: kind === 1 ? "active" : "cleared",
186
+ reason: kind === 1
187
+ ? "The enrolled publisher has an active warning. Keep your wallet disconnected."
188
+ : "The registry has an authorized clearance for the previously published warning.",
189
+ };
190
+ }
191
+ export async function readAdvisory(input, registry, clock = () => new Date()) {
192
+ const hostname = normalizeHostname(input);
193
+ if (!hostname)
194
+ throw new TypeError("Enter a DNS hostname without a URL or port.");
195
+ const base = {
196
+ hostname,
197
+ state: "unconfirmed",
198
+ checkedAt: clock().toISOString(),
199
+ reason: "The BSC testnet registry could not be verified.",
200
+ advisory: null,
201
+ chain: null,
202
+ publisher: null,
203
+ };
204
+ if (!registry) {
205
+ return {
206
+ ...base,
207
+ reason: "Two independent BSC testnet RPC providers and a registry contract must be configured.",
208
+ };
209
+ }
210
+ const [primary, secondary] = registry.providers;
211
+ try {
212
+ const [primaryChain, secondaryChain, primaryHead, secondaryHead] = await Promise.all([
213
+ primary.getChainId(),
214
+ secondary.getChainId(),
215
+ primary.getFinalizedBlock(),
216
+ secondary.getFinalizedBlock(),
217
+ ]);
218
+ if (primaryChain !== chainId || secondaryChain !== chainId) {
219
+ return { ...base, reason: "A configured RPC provider did not report BSC testnet chain ID 97." };
220
+ }
221
+ if (!validBlock(primaryHead) || !validBlock(secondaryHead)) {
222
+ return { ...base, reason: "The configured RPC providers did not return valid finalized blocks." };
223
+ }
224
+ const blockNumber = primaryHead.number < secondaryHead.number
225
+ ? primaryHead.number
226
+ : secondaryHead.number;
227
+ const [primaryBlock, secondaryBlock] = await Promise.all([
228
+ primaryHead.number === blockNumber ? primaryHead : primary.getBlock(blockNumber),
229
+ secondaryHead.number === blockNumber ? secondaryHead : secondary.getBlock(blockNumber),
230
+ ]);
231
+ if (!validBlock(primaryBlock) ||
232
+ !validBlock(secondaryBlock) ||
233
+ primaryBlock.number !== blockNumber ||
234
+ secondaryBlock.number !== blockNumber ||
235
+ primaryBlock.hash.toLowerCase() !== secondaryBlock.hash.toLowerCase() ||
236
+ primaryBlock.timestamp !== secondaryBlock.timestamp) {
237
+ return { ...base, reason: "The RPC providers did not agree on the shared finalized block." };
238
+ }
239
+ const hostKey = keccak256(stringToHex(hostname));
240
+ const [primaryRecord, secondaryRecord] = await Promise.all([
241
+ primary.read(hostKey, primaryBlock.hash),
242
+ secondary.read(hostKey, primaryBlock.hash),
243
+ ]);
244
+ const checkedAt = clock();
245
+ const checked = { ...base, checkedAt: checkedAt.toISOString() };
246
+ const now = BigInt(Math.floor(checkedAt.getTime() / 1_000));
247
+ if (primaryBlock.timestamp < now - maxFinalizedAgeSeconds ||
248
+ primaryBlock.timestamp > now + maxFutureSkewSeconds) {
249
+ return {
250
+ ...checked,
251
+ reason: "The shared finalized block did not pass the freshness check.",
252
+ };
253
+ }
254
+ if (!recordEqual(primaryRecord, secondaryRecord)) {
255
+ return { ...checked, reason: "The RPC providers returned different advisory records." };
256
+ }
257
+ return presentRecord(checked, {
258
+ id: chainId,
259
+ blockNumber: blockNumber.toString(),
260
+ blockHash: primaryBlock.hash.toLowerCase(),
261
+ blockTimestamp: isoTimestamp(primaryBlock.timestamp),
262
+ contractAddress: registry.address,
263
+ }, primaryRecord, primaryBlock.timestamp, now);
264
+ }
265
+ catch {
266
+ return base;
267
+ }
268
+ }
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@shadowbreaker/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Verify ShadowBreaker advisories directly against two BNB Smart Chain testnet RPC providers.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "engines": {
8
+ "node": ">=22"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/shadowbraker-v2/protocol.git",
13
+ "directory": "packages/sdk"
14
+ },
15
+ "homepage": "https://shadowbreaker-bnb-web.vercel.app/how-it-works",
16
+ "bugs": {
17
+ "url": "https://github.com/shadowbraker-v2/protocol/issues"
18
+ },
19
+ "keywords": [
20
+ "shadowbreaker",
21
+ "advisory",
22
+ "bsc",
23
+ "security",
24
+ "viem"
25
+ ],
26
+ "files": [
27
+ "dist",
28
+ "README.md",
29
+ "LICENSE",
30
+ "PROTOCOL.md"
31
+ ],
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/index.d.ts",
35
+ "default": "./dist/index.js"
36
+ }
37
+ },
38
+ "types": "./dist/index.d.ts",
39
+ "sideEffects": false,
40
+ "scripts": {
41
+ "build": "tsc -p tsconfig.json",
42
+ "typecheck": "tsc -p tsconfig.json --noEmit",
43
+ "prepack": "npm run build"
44
+ },
45
+ "dependencies": {
46
+ "viem": "2.58.7"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public",
50
+ "registry": "https://registry.npmjs.org/"
51
+ }
52
+ }