nostr-veil 0.0.1 → 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/LICENCE +21 -0
- package/README.md +187 -0
- package/bin/cli.js +153 -0
- package/bin/config.js +38 -0
- package/dist/_noble-compat.d.ts +14 -0
- package/dist/_noble-compat.d.ts.map +1 -0
- package/dist/_noble-compat.js +18 -0
- package/dist/_noble-compat.js.map +1 -0
- package/dist/duress/alert.d.ts +18 -0
- package/dist/duress/alert.d.ts.map +1 -0
- package/dist/duress/alert.js +20 -0
- package/dist/duress/alert.js.map +1 -0
- package/dist/duress/index.d.ts +4 -0
- package/dist/duress/index.d.ts.map +1 -0
- package/dist/duress/index.js +4 -0
- package/dist/duress/index.js.map +1 -0
- package/dist/duress/monitor.d.ts +10 -0
- package/dist/duress/monitor.d.ts.map +1 -0
- package/dist/duress/monitor.js +73 -0
- package/dist/duress/monitor.js.map +1 -0
- package/dist/duress/types.d.ts +25 -0
- package/dist/duress/types.d.ts.map +1 -0
- package/dist/duress/types.js +2 -0
- package/dist/duress/types.js.map +1 -0
- package/dist/identity/disclosure.d.ts +34 -0
- package/dist/identity/disclosure.d.ts.map +1 -0
- package/dist/identity/disclosure.js +52 -0
- package/dist/identity/disclosure.js.map +1 -0
- package/dist/identity/index.d.ts +5 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +5 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/identity/persona.d.ts +22 -0
- package/dist/identity/persona.d.ts.map +1 -0
- package/dist/identity/persona.js +33 -0
- package/dist/identity/persona.js.map +1 -0
- package/dist/identity/provider.d.ts +23 -0
- package/dist/identity/provider.d.ts.map +1 -0
- package/dist/identity/provider.js +50 -0
- package/dist/identity/provider.js.map +1 -0
- package/dist/identity/types.d.ts +13 -0
- package/dist/identity/types.d.ts.map +1 -0
- package/dist/identity/types.js +2 -0
- package/dist/identity/types.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/nip85/builders.d.ts +73 -0
- package/dist/nip85/builders.d.ts.map +1 -0
- package/dist/nip85/builders.js +126 -0
- package/dist/nip85/builders.js.map +1 -0
- package/dist/nip85/filters.d.ts +36 -0
- package/dist/nip85/filters.d.ts.map +1 -0
- package/dist/nip85/filters.js +41 -0
- package/dist/nip85/filters.js.map +1 -0
- package/dist/nip85/index.d.ts +6 -0
- package/dist/nip85/index.d.ts.map +1 -0
- package/dist/nip85/index.js +6 -0
- package/dist/nip85/index.js.map +1 -0
- package/dist/nip85/parsers.d.ts +44 -0
- package/dist/nip85/parsers.d.ts.map +1 -0
- package/dist/nip85/parsers.js +71 -0
- package/dist/nip85/parsers.js.map +1 -0
- package/dist/nip85/types.d.ts +84 -0
- package/dist/nip85/types.d.ts.map +1 -0
- package/dist/nip85/types.js +16 -0
- package/dist/nip85/types.js.map +1 -0
- package/dist/nip85/validators.d.ts +26 -0
- package/dist/nip85/validators.d.ts.map +1 -0
- package/dist/nip85/validators.js +53 -0
- package/dist/nip85/validators.js.map +1 -0
- package/dist/proof/aggregate.d.ts +23 -0
- package/dist/proof/aggregate.d.ts.map +1 -0
- package/dist/proof/aggregate.js +101 -0
- package/dist/proof/aggregate.js.map +1 -0
- package/dist/proof/circle.d.ts +50 -0
- package/dist/proof/circle.d.ts.map +1 -0
- package/dist/proof/circle.js +97 -0
- package/dist/proof/circle.js.map +1 -0
- package/dist/proof/contribute.d.ts +17 -0
- package/dist/proof/contribute.d.ts.map +1 -0
- package/dist/proof/contribute.js +27 -0
- package/dist/proof/contribute.js.map +1 -0
- package/dist/proof/index.d.ts +6 -0
- package/dist/proof/index.d.ts.map +1 -0
- package/dist/proof/index.js +6 -0
- package/dist/proof/index.js.map +1 -0
- package/dist/proof/types.d.ts +37 -0
- package/dist/proof/types.d.ts.map +1 -0
- package/dist/proof/types.js +2 -0
- package/dist/proof/types.js.map +1 -0
- package/dist/proof/verify.d.ts +7 -0
- package/dist/proof/verify.d.ts.map +1 -0
- package/dist/proof/verify.js +109 -0
- package/dist/proof/verify.js.map +1 -0
- package/dist/scorer/graph.d.ts +14 -0
- package/dist/scorer/graph.d.ts.map +1 -0
- package/dist/scorer/graph.js +71 -0
- package/dist/scorer/graph.js.map +1 -0
- package/dist/scorer/index.d.ts +4 -0
- package/dist/scorer/index.d.ts.map +1 -0
- package/dist/scorer/index.js +4 -0
- package/dist/scorer/index.js.map +1 -0
- package/dist/scorer/rank.d.ts +15 -0
- package/dist/scorer/rank.d.ts.map +1 -0
- package/dist/scorer/rank.js +40 -0
- package/dist/scorer/rank.js.map +1 -0
- package/dist/scorer/types.d.ts +30 -0
- package/dist/scorer/types.d.ts.map +1 -0
- package/dist/scorer/types.js +2 -0
- package/dist/scorer/types.js.map +1 -0
- package/dist/signing.d.ts +54 -0
- package/dist/signing.d.ts.map +1 -0
- package/dist/signing.js +58 -0
- package/dist/signing.js.map +1 -0
- package/llms-full.txt +573 -0
- package/llms.txt +71 -0
- package/package.json +83 -5
- package/index.js +0 -1
package/LICENCE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT Licence
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ForgeSworn
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# nostr-veil
|
|
2
|
+
|
|
3
|
+
[](https://github.com/forgesworn/nostr-veil/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/nostr-veil)
|
|
5
|
+
[](./LICENCE)
|
|
6
|
+
|
|
7
|
+
**Trust scores you can verify without seeing who contributed them.**
|
|
8
|
+
|
|
9
|
+
Anonymous trust assertions for Nostr. LSAG ring signatures over NIP-85 events so endorsements are verifiable but contributors are unidentifiable.
|
|
10
|
+
|
|
11
|
+
**Who is this for?** Nostr client developers building trust systems where contributor privacy matters -- abuse reporting, whistleblowing, journalism, anonymous peer review. If your users can't afford to be identified when vouching for someone, this is the library.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## The Trust Trilemma
|
|
16
|
+
|
|
17
|
+
Today's NIP-85 trust scores ask you to pick two:
|
|
18
|
+
|
|
19
|
+
| Property | NIP-85 today | nostr-veil |
|
|
20
|
+
|-------------|:---:|:---:|
|
|
21
|
+
| Verifiable | ✓ | ✓ |
|
|
22
|
+
| Private | ✗ | ✓ |
|
|
23
|
+
| Portable | ✓ | ✓ |
|
|
24
|
+
|
|
25
|
+
Anyone who can see the assertions can see exactly who judged you. That works fine for benign social signals. It fails completely the moment the subject matter is sensitive -- abuse reporting, whistleblowing, political dissent. The people who need Web of Trust most are the ones who cannot afford to be identified.
|
|
26
|
+
|
|
27
|
+
nostr-veil solves all three. Assertions are standard NIP-85 events that any existing client can consume. Veil-aware clients can go further and verify the cryptographic proofs that back them.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Architecture
|
|
32
|
+
|
|
33
|
+
```mermaid
|
|
34
|
+
graph TB
|
|
35
|
+
subgraph Consumers["Nostr Clients"]
|
|
36
|
+
any["Any NIP-85 client<br/>reads standard assertions"]
|
|
37
|
+
veil["Veil-aware client<br/>verifies ring proofs"]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
subgraph Veil["nostr-veil"]
|
|
41
|
+
proof["nostr-veil/proof<br/>LSAG ring signatures<br/>anonymous contributions<br/>threshold aggregation"]
|
|
42
|
+
nip85["nostr-veil/nip85<br/>Kind 30382–30385 assertions<br/>Kind 10040 providers<br/>builders · parsers · filters"]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
subgraph Crypto["Cryptographic Primitives"]
|
|
46
|
+
ringsig["@forgesworn/ring-sig<br/>SAG / LSAG on secp256k1"]
|
|
47
|
+
noble["@noble/curves + hashes<br/>Schnorr · SHA-256"]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
subgraph Companions["Companion Libraries"]
|
|
51
|
+
nsec["nsec-tree<br/>sub-identity derivation"]
|
|
52
|
+
canary["canary-kit<br/>coercion detection"]
|
|
53
|
+
signet["signet<br/>identity verification"]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
any -->|"read"| nip85
|
|
57
|
+
veil -->|"verify"| proof
|
|
58
|
+
proof -->|"builds on"| nip85
|
|
59
|
+
proof --> ringsig
|
|
60
|
+
nip85 --> noble
|
|
61
|
+
nsec -.->|"personas for"| proof
|
|
62
|
+
canary -.->|"liveness for"| proof
|
|
63
|
+
|
|
64
|
+
style any fill:#3b82f6,color:#fff
|
|
65
|
+
style veil fill:#d97706,color:#000
|
|
66
|
+
style proof fill:#d97706,color:#000
|
|
67
|
+
style nip85 fill:#0d9488,color:#fff
|
|
68
|
+
style ringsig fill:#8b5cf6,color:#fff
|
|
69
|
+
style noble fill:#8b5cf6,color:#fff
|
|
70
|
+
style nsec fill:#374151,color:#e5e7eb
|
|
71
|
+
style canary fill:#374151,color:#e5e7eb
|
|
72
|
+
style signet fill:#374151,color:#e5e7eb
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Quick start
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
npm install nostr-veil
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { createTrustCircle, contributeAssertion, aggregateContributions, verifyProof } from 'nostr-veil'
|
|
85
|
+
|
|
86
|
+
// 1. Define the circle (three anonymous members)
|
|
87
|
+
const circle = createTrustCircle([alicePubkey, bobPubkey, carolPubkey])
|
|
88
|
+
|
|
89
|
+
// 2. Each member contributes independently -- their identity is hidden inside the ring
|
|
90
|
+
const alice = contributeAssertion(circle, subjectPubkey, { followers: 820, rank: 74 }, alicePrivkey, 0)
|
|
91
|
+
const bob = contributeAssertion(circle, subjectPubkey, { followers: 900, rank: 80 }, bobPrivkey, 1)
|
|
92
|
+
|
|
93
|
+
// 3. Aggregate into a standard NIP-85 kind 30382 event
|
|
94
|
+
const assertion = aggregateContributions(circle, subjectPubkey, [alice, bob])
|
|
95
|
+
|
|
96
|
+
// 4. Any client verifies -- two distinct members agreed, no names attached
|
|
97
|
+
const result = verifyProof(assertion)
|
|
98
|
+
// { valid: true, circleSize: 3, threshold: 2, distinctSigners: 2, errors: [] }
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The resulting `assertion` is a plain `EventTemplate` you sign and publish like any other Nostr event.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## API reference
|
|
106
|
+
|
|
107
|
+
### `nostr-veil/nip85` -- NIP-85 foundation
|
|
108
|
+
|
|
109
|
+
| Export | Description |
|
|
110
|
+
|--------|-------------|
|
|
111
|
+
| `buildUserAssertion(pubkey, metrics)` | Build a kind 30382 user assertion event template |
|
|
112
|
+
| `buildEventAssertion(eventId, metrics)` | Build a kind 30383 event assertion |
|
|
113
|
+
| `buildAddressableAssertion(address, metrics)` | Build a kind 30384 addressable assertion |
|
|
114
|
+
| `buildIdentifierAssertion(identifier, kTag, metrics)` | Build a kind 30385 identifier assertion |
|
|
115
|
+
| `buildProviderDeclaration(providers, encryptedContent?)` | Build a kind 10040 provider declaration |
|
|
116
|
+
| `parseAssertion(event)` | Parse a raw event into a `ParsedAssertion` |
|
|
117
|
+
| `validateAssertion(event)` | Validate a NIP-85 assertion -- returns `{ valid, errors }` |
|
|
118
|
+
| `assertionFilter({ kind, subject?, provider? })` | Build a relay query filter for assertions |
|
|
119
|
+
| `providerFilter(pubkey)` | Build a relay query filter for a provider declaration |
|
|
120
|
+
| `NIP85_KINDS` | Kind constants: `USER`, `EVENT`, `ADDRESSABLE`, `IDENTIFIER`, `PROVIDER` |
|
|
121
|
+
|
|
122
|
+
### `nostr-veil/proof` -- Ring-signature proof layer
|
|
123
|
+
|
|
124
|
+
| Export | Description |
|
|
125
|
+
|--------|-------------|
|
|
126
|
+
| `createTrustCircle(memberPubkeys)` | Create a trust circle from an array of pubkeys |
|
|
127
|
+
| `contributeAssertion(circle, subject, metrics, privateKey, memberIndex)` | Produce an anonymous `Contribution` using LSAG |
|
|
128
|
+
| `aggregateContributions(circle, subject, contributions, options?)` | Aggregate contributions into a NIP-85 event with veil tags (default aggregation: median) |
|
|
129
|
+
| `verifyProof(event)` | Verify all LSAG signatures and return a `ProofVerification` |
|
|
130
|
+
| `canonicalMessage(circleId, subject, metrics)` | Compute the canonical message signed by contributors |
|
|
131
|
+
| `computeCircleId(sortedPubkeys)` | Compute the deterministic circle ID (SHA-256 of colon-joined pubkeys) |
|
|
132
|
+
|
|
133
|
+
### Signing utility (root export)
|
|
134
|
+
|
|
135
|
+
| Export | Description |
|
|
136
|
+
|--------|-------------|
|
|
137
|
+
| `signEvent(template, privateKey)` | Sign an unsigned event template with BIP-340 Schnorr -- returns a complete `SignedEvent` |
|
|
138
|
+
| `computeEventId(event)` | Compute the NIP-01 event ID (SHA-256 of canonical serialisation) |
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## How it works
|
|
143
|
+
|
|
144
|
+
Each member of a trust circle calls `contributeAssertion` independently. Under the hood this calls `lsagSign` from `@forgesworn/ring-sig`, which produces a Linkable Spontaneous Anonymous Group signature over the canonical message `{ circleId, subject, metrics }`.
|
|
145
|
+
|
|
146
|
+
The published NIP-85 event carries three extra tags:
|
|
147
|
+
|
|
148
|
+
- `veil-ring` -- the full set of member pubkeys (the ring)
|
|
149
|
+
- `veil-threshold` -- how many contributions were aggregated out of how many members
|
|
150
|
+
- `veil-sig` (one per contribution) -- the serialised LSAG signature and key image
|
|
151
|
+
|
|
152
|
+
A verifier calls `verifyProof`, which:
|
|
153
|
+
|
|
154
|
+
1. Reconstructs each LSAG signature against the ring
|
|
155
|
+
2. Confirms each signature is valid
|
|
156
|
+
3. Checks key images are distinct -- proving each signer contributed at most once (LSAG linkability property)
|
|
157
|
+
4. Confirms the number of valid, distinct signatures meets the threshold
|
|
158
|
+
|
|
159
|
+
At no point does verification require knowing which member produced which signature. The ring is public. The identities of the actual signers are not.
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## Companion projects
|
|
164
|
+
|
|
165
|
+
nostr-veil is one layer of a broader identity and trust stack:
|
|
166
|
+
|
|
167
|
+
- [@forgesworn/ring-sig](https://github.com/forgesworn/ring-sig) -- LSAG ring signatures on secp256k1 (the cryptographic primitive)
|
|
168
|
+
- [nsec-tree](https://github.com/forgesworn/nsec-tree) -- Deterministic sub-identity derivation (compartmentalised personas for trust circles)
|
|
169
|
+
- [canary-kit](https://github.com/forgesworn/canary-kit) -- Coercion-resistant verification and duress detection
|
|
170
|
+
- [signet](https://github.com/forgesworn/signet) -- Decentralised identity verification for Nostr
|
|
171
|
+
- [dominion](https://github.com/forgesworn/dominion) -- Epoch-based encrypted content access control
|
|
172
|
+
|
|
173
|
+
Each project is independently maintained and published. nostr-veil focuses solely on anonymous trust assertions.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## Further reading
|
|
178
|
+
|
|
179
|
+
- [IMPACT.md](./IMPACT.md) -- Problem statement and ecosystem impact
|
|
180
|
+
- [CONTRIBUTING.md](./CONTRIBUTING.md) -- Setup, testing, and PR guidelines
|
|
181
|
+
- [SECURITY.md](./SECURITY.md) -- Vulnerability reporting and cryptographic scope
|
|
182
|
+
- [llms.txt](./llms.txt) -- Machine-readable project summary for LLMs
|
|
183
|
+
- [CLAUDE.md](./CLAUDE.md) -- AI agent instructions for contributing
|
|
184
|
+
|
|
185
|
+
## Licence
|
|
186
|
+
|
|
187
|
+
MIT
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { loadConfig } from './config.js'
|
|
4
|
+
import { signEvent } from '../dist/signing.js'
|
|
5
|
+
import {
|
|
6
|
+
buildUserAssertion,
|
|
7
|
+
buildEventAssertion,
|
|
8
|
+
buildAddressableAssertion,
|
|
9
|
+
buildIdentifierAssertion,
|
|
10
|
+
buildProviderDeclaration,
|
|
11
|
+
} from '../dist/nip85/builders.js'
|
|
12
|
+
import { verifyProof } from '../dist/proof/verify.js'
|
|
13
|
+
|
|
14
|
+
const USAGE = `nostr-veil — anonymous trust assertions for Nostr
|
|
15
|
+
|
|
16
|
+
Usage:
|
|
17
|
+
nostr-veil assert user <pubkey> [--json metrics] Build kind 30382 user assertion
|
|
18
|
+
nostr-veil assert event <event-id> [--json metrics] Build kind 30383 event assertion
|
|
19
|
+
nostr-veil assert address <address> [--json metrics] Build kind 30384 addressable assertion
|
|
20
|
+
nostr-veil assert identifier <id> <k-tag> [--json metrics] Build kind 30385 identifier assertion
|
|
21
|
+
nostr-veil provider-declare [--json entries] Build kind 10040 provider declaration
|
|
22
|
+
nostr-veil verify <event-json> Verify veil ring proof, print result
|
|
23
|
+
nostr-veil --help Show this message
|
|
24
|
+
|
|
25
|
+
Environment:
|
|
26
|
+
NOSTR_SECRET_KEY 64-char hex private key
|
|
27
|
+
NOSTR_SECRET_KEY_FILE Path to secret key file (takes precedence)
|
|
28
|
+
|
|
29
|
+
Output is signed event JSON to stdout. Pipe to other tools for relay publishing.
|
|
30
|
+
`
|
|
31
|
+
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
// Helpers
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
/** Extract --json value from args (the next arg after --json). */
|
|
37
|
+
function extractJsonFlag(args) {
|
|
38
|
+
const idx = args.indexOf('--json')
|
|
39
|
+
if (idx === -1 || idx + 1 >= args.length) return undefined
|
|
40
|
+
try {
|
|
41
|
+
return JSON.parse(args[idx + 1])
|
|
42
|
+
} catch {
|
|
43
|
+
console.error('Error: invalid JSON after --json flag')
|
|
44
|
+
process.exit(1)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
// Commands
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
|
|
52
|
+
function cmdAssert(args) {
|
|
53
|
+
const subcommand = args[0]
|
|
54
|
+
if (!subcommand) {
|
|
55
|
+
console.error('Error: assert requires a subcommand (user, event, address, identifier)')
|
|
56
|
+
process.exit(1)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const { secretKey } = loadConfig()
|
|
60
|
+
const metrics = extractJsonFlag(args) ?? {}
|
|
61
|
+
let template
|
|
62
|
+
|
|
63
|
+
switch (subcommand) {
|
|
64
|
+
case 'user': {
|
|
65
|
+
const pubkey = args[1]
|
|
66
|
+
if (!pubkey) { console.error('Error: assert user requires <pubkey>'); process.exit(1) }
|
|
67
|
+
template = buildUserAssertion(pubkey, metrics)
|
|
68
|
+
break
|
|
69
|
+
}
|
|
70
|
+
case 'event': {
|
|
71
|
+
const eventId = args[1]
|
|
72
|
+
if (!eventId) { console.error('Error: assert event requires <event-id>'); process.exit(1) }
|
|
73
|
+
template = buildEventAssertion(eventId, metrics)
|
|
74
|
+
break
|
|
75
|
+
}
|
|
76
|
+
case 'address': {
|
|
77
|
+
const address = args[1]
|
|
78
|
+
if (!address) { console.error('Error: assert address requires <address>'); process.exit(1) }
|
|
79
|
+
template = buildAddressableAssertion(address, metrics)
|
|
80
|
+
break
|
|
81
|
+
}
|
|
82
|
+
case 'identifier': {
|
|
83
|
+
const id = args[1]
|
|
84
|
+
const kTag = args[2]
|
|
85
|
+
if (!id || !kTag) { console.error('Error: assert identifier requires <id> <k-tag>'); process.exit(1) }
|
|
86
|
+
template = buildIdentifierAssertion(id, kTag, metrics)
|
|
87
|
+
break
|
|
88
|
+
}
|
|
89
|
+
default:
|
|
90
|
+
console.error(`Error: unknown assert subcommand '${subcommand}'`)
|
|
91
|
+
process.exit(1)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const signed = signEvent(template, secretKey)
|
|
95
|
+
console.log(JSON.stringify(signed, null, 2))
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function cmdProviderDeclare(args) {
|
|
99
|
+
const { secretKey } = loadConfig()
|
|
100
|
+
const entries = extractJsonFlag(args) ?? []
|
|
101
|
+
const template = buildProviderDeclaration(entries)
|
|
102
|
+
const signed = signEvent(template, secretKey)
|
|
103
|
+
console.log(JSON.stringify(signed, null, 2))
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function cmdVerify(args) {
|
|
107
|
+
const eventJson = args[0]
|
|
108
|
+
if (!eventJson) {
|
|
109
|
+
console.error('Error: verify requires <event-json>')
|
|
110
|
+
process.exit(1)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
let event
|
|
114
|
+
try {
|
|
115
|
+
event = JSON.parse(eventJson)
|
|
116
|
+
} catch {
|
|
117
|
+
console.error('Error: invalid JSON in event argument')
|
|
118
|
+
process.exit(1)
|
|
119
|
+
}
|
|
120
|
+
if (!event || typeof event !== 'object' || !Array.isArray(event.tags)) {
|
|
121
|
+
console.error('Error: event must be a JSON object with a "tags" array')
|
|
122
|
+
process.exit(1)
|
|
123
|
+
}
|
|
124
|
+
const result = verifyProof(event)
|
|
125
|
+
console.log(JSON.stringify(result, null, 2))
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ---------------------------------------------------------------------------
|
|
129
|
+
// Router
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
|
|
132
|
+
const args = process.argv.slice(2)
|
|
133
|
+
const command = args[0]
|
|
134
|
+
|
|
135
|
+
if (!command || command === '--help' || command === '-h') {
|
|
136
|
+
console.log(USAGE)
|
|
137
|
+
process.exit(0)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
switch (command) {
|
|
141
|
+
case 'assert':
|
|
142
|
+
cmdAssert(args.slice(1))
|
|
143
|
+
break
|
|
144
|
+
case 'provider-declare':
|
|
145
|
+
cmdProviderDeclare(args.slice(1))
|
|
146
|
+
break
|
|
147
|
+
case 'verify':
|
|
148
|
+
cmdVerify(args.slice(1))
|
|
149
|
+
break
|
|
150
|
+
default:
|
|
151
|
+
console.error(`Error: unknown command '${command}'. Run nostr-veil --help for usage.`)
|
|
152
|
+
process.exit(1)
|
|
153
|
+
}
|
package/bin/config.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Load Nostr secret key from environment variables.
|
|
5
|
+
*
|
|
6
|
+
* Environment variables:
|
|
7
|
+
* NOSTR_SECRET_KEY -- 64-char hex private key
|
|
8
|
+
* NOSTR_SECRET_KEY_FILE -- path to secret key file (takes precedence)
|
|
9
|
+
*
|
|
10
|
+
* @returns {{ secretKey: string }}
|
|
11
|
+
*/
|
|
12
|
+
export function loadConfig() {
|
|
13
|
+
const keyFile = process.env.NOSTR_SECRET_KEY_FILE
|
|
14
|
+
const keyEnv = process.env.NOSTR_SECRET_KEY
|
|
15
|
+
|
|
16
|
+
let secretKey
|
|
17
|
+
if (keyFile) {
|
|
18
|
+
secretKey = readFileSync(keyFile, 'utf-8').trim()
|
|
19
|
+
} else if (keyEnv) {
|
|
20
|
+
secretKey = keyEnv.trim()
|
|
21
|
+
} else {
|
|
22
|
+
throw new Error(
|
|
23
|
+
'Set NOSTR_SECRET_KEY or NOSTR_SECRET_KEY_FILE environment variable (64-char hex)'
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!/^[0-9a-f]{64}$/i.test(secretKey)) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
'NOSTR_SECRET_KEY must be a 64-character hex private key'
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Scrub secrets from the environment
|
|
34
|
+
delete process.env.NOSTR_SECRET_KEY
|
|
35
|
+
delete process.env.NOSTR_SECRET_KEY_FILE
|
|
36
|
+
|
|
37
|
+
return { secretKey: secretKey.toLowerCase() }
|
|
38
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type HexOrBytes = string | Uint8Array;
|
|
2
|
+
export declare const schnorr: {
|
|
3
|
+
getPublicKey: (privKey: HexOrBytes) => Uint8Array<ArrayBufferLike>;
|
|
4
|
+
sign: (msg: HexOrBytes, privKey: HexOrBytes) => Uint8Array<ArrayBufferLike>;
|
|
5
|
+
verify: (sig: HexOrBytes, msg: HexOrBytes, pubKey: HexOrBytes) => boolean;
|
|
6
|
+
utils: {
|
|
7
|
+
randomSecretKey: (seed?: Uint8Array) => Uint8Array;
|
|
8
|
+
pointToBytes: (point: import("@noble/curves/abstract/weierstrass.js").WeierstrassPoint<bigint>) => Uint8Array;
|
|
9
|
+
lift_x: (x: bigint) => import("@noble/curves/abstract/weierstrass.js").WeierstrassPoint<bigint>;
|
|
10
|
+
taggedHash: (tag: string, ...messages: Uint8Array[]) => Uint8Array;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export { secp256k1 } from '@noble/curves/secp256k1.js';
|
|
14
|
+
//# sourceMappingURL=_noble-compat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_noble-compat.d.ts","sourceRoot":"","sources":["../src/_noble-compat.ts"],"names":[],"mappings":"AAQA,KAAK,UAAU,GAAG,MAAM,GAAG,UAAU,CAAA;AAMrC,eAAO,MAAM,OAAO;4BACM,UAAU;gBACtB,UAAU,WAAW,UAAU;kBAC7B,UAAU,OAAO,UAAU,UAAU,UAAU;;8BAM4qC,CAAC;;;;;CAH3uC,CAAA;AAED,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compatibility shim for @noble/curves/secp256k1 — noble v2 requires Uint8Array
|
|
3
|
+
* but Nostr tooling conventionally passes hex strings to schnorr functions.
|
|
4
|
+
* This shim re-exports schnorr with hex-string support for the signing layer.
|
|
5
|
+
*/
|
|
6
|
+
import { schnorr as _schnorr } from '@noble/curves/secp256k1.js';
|
|
7
|
+
import { hexToBytes } from '@noble/hashes/utils.js';
|
|
8
|
+
function coerce(v) {
|
|
9
|
+
return typeof v === 'string' ? hexToBytes(v) : v;
|
|
10
|
+
}
|
|
11
|
+
export const schnorr = {
|
|
12
|
+
getPublicKey: (privKey) => _schnorr.getPublicKey(coerce(privKey)),
|
|
13
|
+
sign: (msg, privKey) => _schnorr.sign(coerce(msg), coerce(privKey)),
|
|
14
|
+
verify: (sig, msg, pubKey) => _schnorr.verify(coerce(sig), coerce(msg), coerce(pubKey)),
|
|
15
|
+
utils: _schnorr.utils,
|
|
16
|
+
};
|
|
17
|
+
export { secp256k1 } from '@noble/curves/secp256k1.js';
|
|
18
|
+
//# sourceMappingURL=_noble-compat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_noble-compat.js","sourceRoot":"","sources":["../src/_noble-compat.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAInD,SAAS,MAAM,CAAC,CAAa;IAC3B,OAAO,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAClD,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,YAAY,EAAE,CAAC,OAAmB,EAAE,EAAE,CAAC,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC7E,IAAI,EAAE,CAAC,GAAe,EAAE,OAAmB,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3F,MAAM,EAAE,CAAC,GAAe,EAAE,GAAe,EAAE,MAAkB,EAAE,EAAE,CAC/D,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC3D,KAAK,EAAE,QAAQ,CAAC,KAAK;CACtB,CAAA;AAED,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { decryptDuressAlert } from 'canary-kit/beacon';
|
|
2
|
+
/**
|
|
3
|
+
* Propagate a duress alert for a group member.
|
|
4
|
+
*
|
|
5
|
+
* Derives an AES-256 key from the group seed, builds a duress alert payload,
|
|
6
|
+
* and encrypts it with AES-256-GCM. Returns the encrypted base64 string
|
|
7
|
+
* ready for Nostr event content.
|
|
8
|
+
*
|
|
9
|
+
* @param memberPubkey - 64-character lowercase hex pubkey of the member under duress.
|
|
10
|
+
* @param groupSeed - 64-character lowercase hex group seed (32 bytes).
|
|
11
|
+
* @param location - Optional geohash location with precision, or null/undefined.
|
|
12
|
+
* @returns Encrypted base64 string.
|
|
13
|
+
*/
|
|
14
|
+
export declare function propagateDuressAlert(memberPubkey: string, groupSeed: string, location?: {
|
|
15
|
+
geohash: string;
|
|
16
|
+
precision: number;
|
|
17
|
+
} | null): Promise<string>;
|
|
18
|
+
//# sourceMappingURL=alert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alert.d.ts","sourceRoot":"","sources":["../../src/duress/alert.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAEtD;;;;;;;;;;;GAWG;AACH,wBAAsB,oBAAoB,CACxC,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,EACjB,QAAQ,CAAC,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,GACvD,OAAO,CAAC,MAAM,CAAC,CAOjB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { deriveDuressKey, buildDuressAlert, encryptDuressAlert, } from 'canary-kit/beacon';
|
|
2
|
+
export { decryptDuressAlert } from 'canary-kit/beacon';
|
|
3
|
+
/**
|
|
4
|
+
* Propagate a duress alert for a group member.
|
|
5
|
+
*
|
|
6
|
+
* Derives an AES-256 key from the group seed, builds a duress alert payload,
|
|
7
|
+
* and encrypts it with AES-256-GCM. Returns the encrypted base64 string
|
|
8
|
+
* ready for Nostr event content.
|
|
9
|
+
*
|
|
10
|
+
* @param memberPubkey - 64-character lowercase hex pubkey of the member under duress.
|
|
11
|
+
* @param groupSeed - 64-character lowercase hex group seed (32 bytes).
|
|
12
|
+
* @param location - Optional geohash location with precision, or null/undefined.
|
|
13
|
+
* @returns Encrypted base64 string.
|
|
14
|
+
*/
|
|
15
|
+
export async function propagateDuressAlert(memberPubkey, groupSeed, location) {
|
|
16
|
+
const key = deriveDuressKey(groupSeed);
|
|
17
|
+
const alert = buildDuressAlert(memberPubkey, location ? { ...location, locationSource: 'beacon' } : null);
|
|
18
|
+
return encryptDuressAlert(key, alert);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=alert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alert.js","sourceRoot":"","sources":["../../src/duress/alert.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAEtD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,YAAoB,EACpB,SAAiB,EACjB,QAAwD;IAExD,MAAM,GAAG,GAAG,eAAe,CAAC,SAAS,CAAC,CAAA;IACtC,MAAM,KAAK,GAAG,gBAAgB,CAC5B,YAAY,EACZ,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,QAAQ,EAAE,cAAc,EAAE,QAAiB,EAAE,CAAC,CAAC,CAAC,IAAI,CACrE,CAAA;IACD,OAAO,kBAAkB,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;AACvC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/duress/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/duress/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DuressMonitor, DuressMonitorOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create a timer-based duress monitor.
|
|
4
|
+
*
|
|
5
|
+
* Tracks heartbeats per member pubkey. When a member fails to check in
|
|
6
|
+
* within `toleranceMs`, a duress event is emitted. Pure state machine --
|
|
7
|
+
* no relay interaction.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createDuressMonitor(options: DuressMonitorOptions): DuressMonitor;
|
|
10
|
+
//# sourceMappingURL=monitor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monitor.d.ts","sourceRoot":"","sources":["../../src/duress/monitor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,aAAa,EACb,oBAAoB,EAErB,MAAM,YAAY,CAAA;AAOnB;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAkEhF"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a timer-based duress monitor.
|
|
3
|
+
*
|
|
4
|
+
* Tracks heartbeats per member pubkey. When a member fails to check in
|
|
5
|
+
* within `toleranceMs`, a duress event is emitted. Pure state machine --
|
|
6
|
+
* no relay interaction.
|
|
7
|
+
*/
|
|
8
|
+
export function createDuressMonitor(options) {
|
|
9
|
+
const { toleranceMs } = options;
|
|
10
|
+
const members = new Map();
|
|
11
|
+
const handlers = [];
|
|
12
|
+
let running = false;
|
|
13
|
+
function emit(event) {
|
|
14
|
+
for (const handler of handlers)
|
|
15
|
+
handler(event);
|
|
16
|
+
}
|
|
17
|
+
function scheduleTimeout(pubkey, lastSeen) {
|
|
18
|
+
return setTimeout(() => {
|
|
19
|
+
const now = Date.now();
|
|
20
|
+
const elapsed = now - lastSeen;
|
|
21
|
+
const level = elapsed >= toleranceMs * 2 ? 'critical' : 'warning';
|
|
22
|
+
emit({
|
|
23
|
+
type: 'heartbeat-missed',
|
|
24
|
+
pubkey,
|
|
25
|
+
lastSeen,
|
|
26
|
+
elapsed,
|
|
27
|
+
level,
|
|
28
|
+
});
|
|
29
|
+
}, toleranceMs);
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
heartbeat(pubkey) {
|
|
33
|
+
if (!running)
|
|
34
|
+
return;
|
|
35
|
+
const now = Date.now();
|
|
36
|
+
const existing = members.get(pubkey);
|
|
37
|
+
if (existing)
|
|
38
|
+
clearTimeout(existing.timeout);
|
|
39
|
+
members.set(pubkey, {
|
|
40
|
+
lastSeen: now,
|
|
41
|
+
timeout: scheduleTimeout(pubkey, now),
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
start() {
|
|
45
|
+
running = true;
|
|
46
|
+
},
|
|
47
|
+
stop() {
|
|
48
|
+
running = false;
|
|
49
|
+
for (const entry of members.values()) {
|
|
50
|
+
clearTimeout(entry.timeout);
|
|
51
|
+
}
|
|
52
|
+
members.clear();
|
|
53
|
+
},
|
|
54
|
+
on(_event, handler) {
|
|
55
|
+
handlers.push(handler);
|
|
56
|
+
},
|
|
57
|
+
getState() {
|
|
58
|
+
const now = Date.now();
|
|
59
|
+
const state = new Map();
|
|
60
|
+
for (const [pubkey, entry] of members) {
|
|
61
|
+
const elapsed = now - entry.lastSeen;
|
|
62
|
+
let status = 'active';
|
|
63
|
+
if (elapsed >= toleranceMs * 2)
|
|
64
|
+
status = 'critical';
|
|
65
|
+
else if (elapsed >= toleranceMs)
|
|
66
|
+
status = 'warning';
|
|
67
|
+
state.set(pubkey, { pubkey, lastSeen: entry.lastSeen, status });
|
|
68
|
+
}
|
|
69
|
+
return state;
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=monitor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"monitor.js","sourceRoot":"","sources":["../../src/duress/monitor.ts"],"names":[],"mappings":"AAYA;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAA6B;IAC/D,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAA;IAC/B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAA;IAC9C,MAAM,QAAQ,GAAoC,EAAE,CAAA;IACpD,IAAI,OAAO,GAAG,KAAK,CAAA;IAEnB,SAAS,IAAI,CAAC,KAAkB;QAC9B,KAAK,MAAM,OAAO,IAAI,QAAQ;YAAE,OAAO,CAAC,KAAK,CAAC,CAAA;IAChD,CAAC;IAED,SAAS,eAAe,CAAC,MAAc,EAAE,QAAgB;QACvD,OAAO,UAAU,CAAC,GAAG,EAAE;YACrB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;YACtB,MAAM,OAAO,GAAG,GAAG,GAAG,QAAQ,CAAA;YAC9B,MAAM,KAAK,GAAG,OAAO,IAAI,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAA;YACjE,IAAI,CAAC;gBACH,IAAI,EAAE,kBAAkB;gBACxB,MAAM;gBACN,QAAQ;gBACR,OAAO;gBACP,KAAK;aACN,CAAC,CAAA;QACJ,CAAC,EAAE,WAAW,CAAC,CAAA;IACjB,CAAC;IAED,OAAO;QACL,SAAS,CAAC,MAAc;YACtB,IAAI,CAAC,OAAO;gBAAE,OAAM;YACpB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;YACtB,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;YACpC,IAAI,QAAQ;gBAAE,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;YAC5C,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE;gBAClB,QAAQ,EAAE,GAAG;gBACb,OAAO,EAAE,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC;aACtC,CAAC,CAAA;QACJ,CAAC;QAED,KAAK;YACH,OAAO,GAAG,IAAI,CAAA;QAChB,CAAC;QAED,IAAI;YACF,OAAO,GAAG,KAAK,CAAA;YACf,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;gBACrC,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;YAC7B,CAAC;YACD,OAAO,CAAC,KAAK,EAAE,CAAA;QACjB,CAAC;QAED,EAAE,CAAC,MAAgB,EAAE,OAAiC;YACpD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACxB,CAAC;QAED,QAAQ;YACN,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;YACtB,MAAM,KAAK,GAAG,IAAI,GAAG,EAA0B,CAAA;YAC/C,KAAK,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;gBACtC,MAAM,OAAO,GAAG,GAAG,GAAG,KAAK,CAAC,QAAQ,CAAA;gBACpC,IAAI,MAAM,GAA6B,QAAQ,CAAA;gBAC/C,IAAI,OAAO,IAAI,WAAW,GAAG,CAAC;oBAAE,MAAM,GAAG,UAAU,CAAA;qBAC9C,IAAI,OAAO,IAAI,WAAW;oBAAE,MAAM,GAAG,SAAS,CAAA;gBACnD,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAA;YACjE,CAAC;YACD,OAAO,KAAK,CAAA;QACd,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type AlertLevel = 'warning' | 'critical';
|
|
2
|
+
export interface HeartbeatState {
|
|
3
|
+
pubkey: string;
|
|
4
|
+
lastSeen: number;
|
|
5
|
+
status: 'active' | 'warning' | 'critical';
|
|
6
|
+
}
|
|
7
|
+
export interface DuressEvent {
|
|
8
|
+
type: 'heartbeat-missed';
|
|
9
|
+
pubkey: string;
|
|
10
|
+
lastSeen: number;
|
|
11
|
+
elapsed: number;
|
|
12
|
+
level: AlertLevel;
|
|
13
|
+
}
|
|
14
|
+
export interface DuressMonitor {
|
|
15
|
+
heartbeat(pubkey: string): void;
|
|
16
|
+
start(): void;
|
|
17
|
+
stop(): void;
|
|
18
|
+
on(event: 'duress', handler: (e: DuressEvent) => void): void;
|
|
19
|
+
getState(): Map<string, HeartbeatState>;
|
|
20
|
+
}
|
|
21
|
+
export interface DuressMonitorOptions {
|
|
22
|
+
toleranceMs: number;
|
|
23
|
+
checkIntervalMs: number;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/duress/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,UAAU,CAAA;AAE/C,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,UAAU,CAAA;CAC1C;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,kBAAkB,CAAA;IACxB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,UAAU,CAAA;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,KAAK,IAAI,IAAI,CAAA;IACb,IAAI,IAAI,IAAI,CAAA;IACZ,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,WAAW,KAAK,IAAI,GAAG,IAAI,CAAA;IAC5D,QAAQ,IAAI,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;CACxC;AAED,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAA;IACnB,eAAe,EAAE,MAAM,CAAA;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/duress/types.ts"],"names":[],"mappings":""}
|