@ritkey/sdk 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 +21 -0
- package/README.md +235 -0
- package/dist/client/alerts.d.ts +29 -0
- package/dist/client/alerts.d.ts.map +1 -0
- package/dist/client/alerts.js +36 -0
- package/dist/client/alerts.js.map +1 -0
- package/dist/client/index.d.ts +32 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +38 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/wallets.d.ts +95 -0
- package/dist/client/wallets.d.ts.map +1 -0
- package/dist/client/wallets.js +95 -0
- package/dist/client/wallets.js.map +1 -0
- package/dist/client/webhooks.d.ts +47 -0
- package/dist/client/webhooks.d.ts.map +1 -0
- package/dist/client/webhooks.js +49 -0
- package/dist/client/webhooks.js.map +1 -0
- package/dist/events/poller.d.ts +57 -0
- package/dist/events/poller.d.ts.map +1 -0
- package/dist/events/poller.js +121 -0
- package/dist/events/poller.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/transport.d.ts +21 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +83 -0
- package/dist/transport.js.map +1 -0
- package/dist/types.d.ts +193 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +20 -0
- package/dist/types.js.map +1 -0
- package/dist/verify/index.d.ts +58 -0
- package/dist/verify/index.d.ts.map +1 -0
- package/dist/verify/index.js +104 -0
- package/dist/verify/index.js.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webhook subscription management.
|
|
3
|
+
*
|
|
4
|
+
* POST /webhooks create()
|
|
5
|
+
* GET /webhooks list()
|
|
6
|
+
* GET /webhooks/events listEventTypes()
|
|
7
|
+
* GET /webhooks/:id get(id)
|
|
8
|
+
* PATCH /webhooks/:id update(id, ...)
|
|
9
|
+
* DELETE /webhooks/:id delete(id)
|
|
10
|
+
* POST /webhooks/:id/test test(id)
|
|
11
|
+
* GET /webhooks/:id/deliveries listDeliveries(id)
|
|
12
|
+
*/
|
|
13
|
+
export class WebhooksClient {
|
|
14
|
+
http;
|
|
15
|
+
constructor(http) {
|
|
16
|
+
this.http = http;
|
|
17
|
+
}
|
|
18
|
+
/** Create a new webhook subscription. Response includes `secret` — save it. */
|
|
19
|
+
async create(input) {
|
|
20
|
+
return this.http.request('POST', '/webhooks', input);
|
|
21
|
+
}
|
|
22
|
+
async list() {
|
|
23
|
+
return this.http.request('GET', '/webhooks');
|
|
24
|
+
}
|
|
25
|
+
async listEventTypes() {
|
|
26
|
+
return this.http.request('GET', '/webhooks/events');
|
|
27
|
+
}
|
|
28
|
+
async get(subscriptionId) {
|
|
29
|
+
return this.http.request('GET', `/webhooks/${encodeURIComponent(subscriptionId)}`);
|
|
30
|
+
}
|
|
31
|
+
async update(subscriptionId, patch) {
|
|
32
|
+
return this.http.request('PATCH', `/webhooks/${encodeURIComponent(subscriptionId)}`, patch);
|
|
33
|
+
}
|
|
34
|
+
async delete(subscriptionId) {
|
|
35
|
+
await this.http.request('DELETE', `/webhooks/${encodeURIComponent(subscriptionId)}`);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Fire a `webhook.test` event to this subscription only.
|
|
39
|
+
* Useful for verifying connectivity and HMAC verification on your receiver.
|
|
40
|
+
*/
|
|
41
|
+
async test(subscriptionId) {
|
|
42
|
+
return this.http.request('POST', `/webhooks/${encodeURIComponent(subscriptionId)}/test`);
|
|
43
|
+
}
|
|
44
|
+
async listDeliveries(subscriptionId, opts) {
|
|
45
|
+
const qs = opts?.limit ? `?limit=${opts.limit}` : '';
|
|
46
|
+
return this.http.request('GET', `/webhooks/${encodeURIComponent(subscriptionId)}/deliveries${qs}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=webhooks.js.map
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AAC,cAAc,CAAC,OAAO,CACvD,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAClB,cAAsB,EACtB,IAAyB;QAEzB,MAAM,EAAE,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CACtB,KAAK,EACL,aAAa,kBAAkB,CAAC,cAAc,CAAC,cAAc,EAAE,EAAE,CAClE,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed event poller.
|
|
3
|
+
*
|
|
4
|
+
* For apps that don't want to operate a public HTTPS endpoint, the SDK can
|
|
5
|
+
* poll `GET /events` and emit events to callbacks. This is the fallback for
|
|
6
|
+
* environments where webhooks aren't practical (CLIs, scripts, dev loops).
|
|
7
|
+
*
|
|
8
|
+
* Production traffic should still use webhooks — polling is rate-limited
|
|
9
|
+
* by the underlying service and burns more API budget.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* const stop = client.events.subscribe({
|
|
13
|
+
* types: ['tx.sent', 'wallet.funded'],
|
|
14
|
+
* onEvent: (event) => console.log(event),
|
|
15
|
+
* });
|
|
16
|
+
* // ... later
|
|
17
|
+
* stop();
|
|
18
|
+
*/
|
|
19
|
+
import type { HttpTransport } from '../transport.js';
|
|
20
|
+
import type { RitkeyEvent, EventType } from '../types.js';
|
|
21
|
+
export interface SubscribeOptions {
|
|
22
|
+
/** Subset of event types to filter on. Default: all. */
|
|
23
|
+
types?: EventType[];
|
|
24
|
+
/** Restrict to a specific wallet. */
|
|
25
|
+
walletId?: string;
|
|
26
|
+
/** Maximum events to fetch per poll. Default: 50. */
|
|
27
|
+
batchSize?: number;
|
|
28
|
+
/** Poll interval in milliseconds. Default: 3000. */
|
|
29
|
+
intervalMs?: number;
|
|
30
|
+
/** Per-event callback. */
|
|
31
|
+
onEvent: (event: RitkeyEvent) => void | Promise<void>;
|
|
32
|
+
/** Optional error handler. If not set, errors are logged with console.error. */
|
|
33
|
+
onError?: (err: unknown) => void;
|
|
34
|
+
}
|
|
35
|
+
/** Returned by subscribe() — call it to stop polling. */
|
|
36
|
+
export type StopFn = () => void;
|
|
37
|
+
export declare class EventsClient {
|
|
38
|
+
private readonly http;
|
|
39
|
+
constructor(http: HttpTransport);
|
|
40
|
+
/**
|
|
41
|
+
* Subscribe to events via polling. Returns a stop function.
|
|
42
|
+
*
|
|
43
|
+
* The poller tracks the most-recent event id it has seen to avoid emitting
|
|
44
|
+
* duplicates across polls (server returns events newest-first by created_at;
|
|
45
|
+
* we de-dupe client-side using id).
|
|
46
|
+
*/
|
|
47
|
+
subscribe(opts: SubscribeOptions): StopFn;
|
|
48
|
+
/**
|
|
49
|
+
* One-shot fetch of recent events (no polling).
|
|
50
|
+
*/
|
|
51
|
+
list(opts?: {
|
|
52
|
+
walletId?: string;
|
|
53
|
+
type?: EventType;
|
|
54
|
+
limit?: number;
|
|
55
|
+
}): Promise<RitkeyEvent[]>;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=poller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poller.d.ts","sourceRoot":"","sources":["../../src/events/poller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE1D,MAAM,WAAW,gBAAgB;IAC/B,wDAAwD;IACxD,KAAK,CAAC,EAAE,SAAS,EAAE,CAAC;IACpB,qCAAqC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0BAA0B;IAC1B,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,gFAAgF;IAChF,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;CAClC;AAED,yDAAyD;AACzD,MAAM,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC;AAOhC,qBAAa,YAAY;IACX,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,aAAa;IAEhD;;;;;;OAMG;IACH,SAAS,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM;IA0EzC;;OAEG;IACG,IAAI,CAAC,IAAI,CAAC,EAAE;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,IAAI,CAAC,EAAE,SAAS,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;CAS3B"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed event poller.
|
|
3
|
+
*
|
|
4
|
+
* For apps that don't want to operate a public HTTPS endpoint, the SDK can
|
|
5
|
+
* poll `GET /events` and emit events to callbacks. This is the fallback for
|
|
6
|
+
* environments where webhooks aren't practical (CLIs, scripts, dev loops).
|
|
7
|
+
*
|
|
8
|
+
* Production traffic should still use webhooks — polling is rate-limited
|
|
9
|
+
* by the underlying service and burns more API budget.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* const stop = client.events.subscribe({
|
|
13
|
+
* types: ['tx.sent', 'wallet.funded'],
|
|
14
|
+
* onEvent: (event) => console.log(event),
|
|
15
|
+
* });
|
|
16
|
+
* // ... later
|
|
17
|
+
* stop();
|
|
18
|
+
*/
|
|
19
|
+
export class EventsClient {
|
|
20
|
+
http;
|
|
21
|
+
constructor(http) {
|
|
22
|
+
this.http = http;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Subscribe to events via polling. Returns a stop function.
|
|
26
|
+
*
|
|
27
|
+
* The poller tracks the most-recent event id it has seen to avoid emitting
|
|
28
|
+
* duplicates across polls (server returns events newest-first by created_at;
|
|
29
|
+
* we de-dupe client-side using id).
|
|
30
|
+
*/
|
|
31
|
+
subscribe(opts) {
|
|
32
|
+
const intervalMs = opts.intervalMs ?? 3000;
|
|
33
|
+
const batchSize = opts.batchSize ?? 50;
|
|
34
|
+
const filterTypes = opts.types ? new Set(opts.types) : null;
|
|
35
|
+
const seenIds = new Set();
|
|
36
|
+
// Don't replay the existing event backlog on first poll — only emit
|
|
37
|
+
// events we observe AFTER subscribe() is called. We seed `seenIds` with
|
|
38
|
+
// the current tail of the log on first fetch.
|
|
39
|
+
let primed = false;
|
|
40
|
+
let stopped = false;
|
|
41
|
+
const poll = async () => {
|
|
42
|
+
if (stopped)
|
|
43
|
+
return;
|
|
44
|
+
try {
|
|
45
|
+
const qs = [`limit=${batchSize}`];
|
|
46
|
+
if (opts.walletId)
|
|
47
|
+
qs.push(`walletId=${encodeURIComponent(opts.walletId)}`);
|
|
48
|
+
// We don't pass `type=` because we may want to subscribe to N types;
|
|
49
|
+
// we filter client-side instead.
|
|
50
|
+
const res = await this.http.request('GET', `/events?${qs.join('&')}`);
|
|
51
|
+
const events = res.events ?? [];
|
|
52
|
+
if (!primed) {
|
|
53
|
+
// Seed the seen-set with everything currently in the log;
|
|
54
|
+
// we don't replay history.
|
|
55
|
+
for (const ev of events)
|
|
56
|
+
seenIds.add(ev.id);
|
|
57
|
+
primed = true;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
// Emit newest events we haven't seen yet, in chronological order.
|
|
61
|
+
const fresh = events.filter((ev) => !seenIds.has(ev.id)).reverse();
|
|
62
|
+
for (const ev of fresh) {
|
|
63
|
+
seenIds.add(ev.id);
|
|
64
|
+
if (filterTypes && !filterTypes.has(ev.type))
|
|
65
|
+
continue;
|
|
66
|
+
try {
|
|
67
|
+
await opts.onEvent(ev);
|
|
68
|
+
}
|
|
69
|
+
catch (handlerErr) {
|
|
70
|
+
if (opts.onError)
|
|
71
|
+
opts.onError(handlerErr);
|
|
72
|
+
else
|
|
73
|
+
console.error('[ritkey/sdk] event handler threw:', handlerErr);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Prevent seenIds from growing unbounded. Keep last ~10k.
|
|
77
|
+
if (seenIds.size > 10_000) {
|
|
78
|
+
const overflow = seenIds.size - 5_000;
|
|
79
|
+
const it = seenIds.values();
|
|
80
|
+
for (let i = 0; i < overflow; i++) {
|
|
81
|
+
const next = it.next();
|
|
82
|
+
if (next.done)
|
|
83
|
+
break;
|
|
84
|
+
seenIds.delete(next.value);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
if (opts.onError)
|
|
90
|
+
opts.onError(err);
|
|
91
|
+
else
|
|
92
|
+
console.error('[ritkey/sdk] poll failed:', err);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
// Kick off first poll immediately, then on the interval.
|
|
96
|
+
void poll();
|
|
97
|
+
const handle = setInterval(() => void poll(), intervalMs);
|
|
98
|
+
// Don't block process exit on the timer.
|
|
99
|
+
handle.unref?.();
|
|
100
|
+
return () => {
|
|
101
|
+
stopped = true;
|
|
102
|
+
clearInterval(handle);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* One-shot fetch of recent events (no polling).
|
|
107
|
+
*/
|
|
108
|
+
async list(opts) {
|
|
109
|
+
const qs = [];
|
|
110
|
+
if (opts?.walletId)
|
|
111
|
+
qs.push(`walletId=${encodeURIComponent(opts.walletId)}`);
|
|
112
|
+
if (opts?.type)
|
|
113
|
+
qs.push(`type=${encodeURIComponent(opts.type)}`);
|
|
114
|
+
if (opts?.limit)
|
|
115
|
+
qs.push(`limit=${opts.limit}`);
|
|
116
|
+
const path = `/events${qs.length ? '?' + qs.join('&') : ''}`;
|
|
117
|
+
const res = await this.http.request('GET', path);
|
|
118
|
+
return res.events ?? [];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=poller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poller.js","sourceRoot":"","sources":["../../src/events/poller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AA4BH,MAAM,OAAO,YAAY;IACM;IAA7B,YAA6B,IAAmB;QAAnB,SAAI,GAAJ,IAAI,CAAe;IAAG,CAAC;IAEpD;;;;;;OAMG;IACH,SAAS,CAAC,IAAsB;QAC9B,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC;QAC3C,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC;QACvC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC5D,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;QAClC,oEAAoE;QACpE,wEAAwE;QACxE,8CAA8C;QAC9C,IAAI,MAAM,GAAG,KAAK,CAAC;QACnB,IAAI,OAAO,GAAG,KAAK,CAAC;QAEpB,MAAM,IAAI,GAAG,KAAK,IAAmB,EAAE;YACrC,IAAI,OAAO;gBAAE,OAAO;YACpB,IAAI,CAAC;gBACH,MAAM,EAAE,GAAa,CAAC,SAAS,SAAS,EAAE,CAAC,CAAC;gBAC5C,IAAI,IAAI,CAAC,QAAQ;oBAAE,EAAE,CAAC,IAAI,CAAC,YAAY,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;gBAC5E,qEAAqE;gBACrE,iCAAiC;gBACjC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CACjC,KAAK,EACL,WAAW,EAAE,C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,GAAG,UAAU,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QAC7D,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAqB,KAAK,EAAE,IAAI,CAAC,CAAC;QACrE,OAAO,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC;IAC1B,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ritkey/sdk — TypeScript SDK for Ritkey
|
|
3
|
+
*
|
|
4
|
+
* Public surface:
|
|
5
|
+
* - RitkeyClient: wallet, webhook, events operations
|
|
6
|
+
* - verifyWebhook: receiver-side HMAC verification helper
|
|
7
|
+
* - isEvent: type narrower for verified events
|
|
8
|
+
* - All public types
|
|
9
|
+
*/
|
|
10
|
+
export { RitkeyClient } from './client/index.js';
|
|
11
|
+
export { WalletsClient } from './client/wallets.js';
|
|
12
|
+
export { WebhooksClient } from './client/webhooks.js';
|
|
13
|
+
export { AlertsClient } from './client/alerts.js';
|
|
14
|
+
export { EventsClient } from './events/poller.js';
|
|
15
|
+
export { verifyWebhook, isEvent } from './verify/index.js';
|
|
16
|
+
export type { VerifyOptions, VerifyResult } from './verify/index.js';
|
|
17
|
+
export type { SubscribeOptions, StopFn } from './events/poller.js';
|
|
18
|
+
export * from './types.js';
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC3D,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACrE,YAAY,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACnE,cAAc,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ritkey/sdk — TypeScript SDK for Ritkey
|
|
3
|
+
*
|
|
4
|
+
* Public surface:
|
|
5
|
+
* - RitkeyClient: wallet, webhook, events operations
|
|
6
|
+
* - verifyWebhook: receiver-side HMAC verification helper
|
|
7
|
+
* - isEvent: type narrower for verified events
|
|
8
|
+
* - All public types
|
|
9
|
+
*/
|
|
10
|
+
export { RitkeyClient } from './client/index.js';
|
|
11
|
+
export { WalletsClient } from './client/wallets.js';
|
|
12
|
+
export { WebhooksClient } from './client/webhooks.js';
|
|
13
|
+
export { AlertsClient } from './client/alerts.js';
|
|
14
|
+
export { EventsClient } from './events/poller.js';
|
|
15
|
+
export { verifyWebhook, isEvent } from './verify/index.js';
|
|
16
|
+
export * from './types.js';
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG3D,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP transport for the Ritkey SDK.
|
|
3
|
+
*
|
|
4
|
+
* Wraps `fetch` with:
|
|
5
|
+
* - default headers (Authorization + content-type)
|
|
6
|
+
* - per-request timeout (AbortController)
|
|
7
|
+
* - JSON serialization/parsing
|
|
8
|
+
* - rich error type that captures status, code, and parsed body
|
|
9
|
+
*/
|
|
10
|
+
import { type RitkeyClientConfig } from './types.js';
|
|
11
|
+
export declare class HttpTransport {
|
|
12
|
+
private readonly baseUrl;
|
|
13
|
+
private readonly apiKey?;
|
|
14
|
+
private readonly fetchImpl;
|
|
15
|
+
private readonly timeoutMs;
|
|
16
|
+
constructor(config: RitkeyClientConfig);
|
|
17
|
+
request<T = unknown>(method: 'GET' | 'POST' | 'PATCH' | 'DELETE', path: string, body?: unknown, opts?: {
|
|
18
|
+
timeoutMs?: number;
|
|
19
|
+
}): Promise<T>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAe,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAIlE,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAU;IACpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAEvB,MAAM,EAAE,kBAAkB;IAehC,OAAO,CAAC,CAAC,GAAG,OAAO,EACvB,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,EAC3C,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,OAAO,EACd,IAAI,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAC5B,OAAO,CAAC,CAAC,CAAC;CAwDd"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP transport for the Ritkey SDK.
|
|
3
|
+
*
|
|
4
|
+
* Wraps `fetch` with:
|
|
5
|
+
* - default headers (Authorization + content-type)
|
|
6
|
+
* - per-request timeout (AbortController)
|
|
7
|
+
* - JSON serialization/parsing
|
|
8
|
+
* - rich error type that captures status, code, and parsed body
|
|
9
|
+
*/
|
|
10
|
+
import { RitkeyError } from './types.js';
|
|
11
|
+
export class HttpTransport {
|
|
12
|
+
baseUrl;
|
|
13
|
+
apiKey;
|
|
14
|
+
fetchImpl;
|
|
15
|
+
timeoutMs;
|
|
16
|
+
constructor(config) {
|
|
17
|
+
if (!config.baseUrl)
|
|
18
|
+
throw new Error('RitkeyClient: baseUrl is required');
|
|
19
|
+
// Strip trailing slash so path joins are simple.
|
|
20
|
+
this.baseUrl = config.baseUrl.replace(/\/+$/, '');
|
|
21
|
+
this.apiKey = config.apiKey;
|
|
22
|
+
this.fetchImpl = (config.fetch ?? globalThis.fetch).bind(globalThis);
|
|
23
|
+
this.timeoutMs = config.timeoutMs ?? 30_000;
|
|
24
|
+
if (typeof this.fetchImpl !== 'function') {
|
|
25
|
+
throw new Error('RitkeyClient: no fetch implementation available. Use Node 18+ or pass `fetch` in the config.');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async request(method, path, body, opts) {
|
|
29
|
+
const url = `${this.baseUrl}${path.startsWith('/') ? '' : '/'}${path}`;
|
|
30
|
+
const controller = new AbortController();
|
|
31
|
+
const timeout = setTimeout(() => controller.abort(), opts?.timeoutMs ?? this.timeoutMs);
|
|
32
|
+
const headers = {
|
|
33
|
+
Accept: 'application/json',
|
|
34
|
+
};
|
|
35
|
+
if (this.apiKey)
|
|
36
|
+
headers['Authorization'] = `Bearer ${this.apiKey}`;
|
|
37
|
+
if (body !== undefined)
|
|
38
|
+
headers['Content-Type'] = 'application/json';
|
|
39
|
+
let res;
|
|
40
|
+
try {
|
|
41
|
+
res = await this.fetchImpl(url, {
|
|
42
|
+
method,
|
|
43
|
+
headers,
|
|
44
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
45
|
+
signal: controller.signal,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
clearTimeout(timeout);
|
|
50
|
+
if (err?.name === 'AbortError') {
|
|
51
|
+
throw new RitkeyError(0, `Request timed out after ${opts?.timeoutMs ?? this.timeoutMs}ms`, null);
|
|
52
|
+
}
|
|
53
|
+
throw new RitkeyError(0, err?.message ?? 'Network error', null);
|
|
54
|
+
}
|
|
55
|
+
clearTimeout(timeout);
|
|
56
|
+
// 204 No Content
|
|
57
|
+
if (res.status === 204)
|
|
58
|
+
return undefined;
|
|
59
|
+
// Parse JSON (may be empty string).
|
|
60
|
+
const text = await res.text();
|
|
61
|
+
let parsed = null;
|
|
62
|
+
if (text.length > 0) {
|
|
63
|
+
try {
|
|
64
|
+
parsed = JSON.parse(text);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// Server returned non-JSON. Surface as a string body on the error.
|
|
68
|
+
if (!res.ok) {
|
|
69
|
+
throw new RitkeyError(res.status, `HTTP ${res.status}: ${text.slice(0, 200)}`, text);
|
|
70
|
+
}
|
|
71
|
+
return text;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (!res.ok) {
|
|
75
|
+
const message = (parsed && typeof parsed === 'object' && (parsed.error ?? parsed.message)) ||
|
|
76
|
+
`HTTP ${res.status}`;
|
|
77
|
+
const code = parsed && typeof parsed === 'object' ? parsed.code : undefined;
|
|
78
|
+
throw new RitkeyError(res.status, String(message), parsed, code);
|
|
79
|
+
}
|
|
80
|
+
return parsed;
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,IAAI,MAAM,GAAQ,IAAI,CAAC;QACvB,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpB,IAAI,CAAC;gBACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC5B,CAAC;YAAC,MAAM,CAAC;gBACP,mEAAmE;gBACnE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;oBACZ,MAAM,IAAI,WAAW,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,GAAG,CAAC,MAAM,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;gBACvF,CAAC;gBACD,OAAO,IAAoB,CAAC;YAC9B,CAAC;QACH,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,MAAM,OAAO,GACX,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;gBAC1E,QAAQ,GAAG,CAAC,MAAM,EAAE,CAAC;YACvB,MAAM,IAAI,GAAG,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;YAC5E,MAAM,IAAI,WAAW,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QACnE,CAAC;QAED,OAAO,MAAW,CAAC;IACrB,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for the Ritkey SDK.
|
|
3
|
+
*
|
|
4
|
+
* These mirror the wire format of the @ritkey/service HTTP API. Where the
|
|
5
|
+
* server returns extra `_notice` / `_security` documentation fields, the SDK
|
|
6
|
+
* forwards them so apps can show them to users on first wallet creation.
|
|
7
|
+
*/
|
|
8
|
+
export type WalletType = 'xor' | 'threshold';
|
|
9
|
+
export type WalletStatus = 'active' | 'frozen' | 'archived';
|
|
10
|
+
/** Full wallet view from POST /wallets and POST /wallets/import (creation responses). */
|
|
11
|
+
export interface CreatedWallet {
|
|
12
|
+
walletId: string;
|
|
13
|
+
address: string;
|
|
14
|
+
publicKey: string;
|
|
15
|
+
/** Returned ONCE — save it. Used as one of two shares for signing. */
|
|
16
|
+
agentShard: string;
|
|
17
|
+
/** Returned ONCE — store offline (cold storage). The third share. */
|
|
18
|
+
backupShard: string;
|
|
19
|
+
walletType: WalletType;
|
|
20
|
+
threshold: number;
|
|
21
|
+
totalShares: number;
|
|
22
|
+
label: string;
|
|
23
|
+
createdAt: string;
|
|
24
|
+
}
|
|
25
|
+
/** Wallet view from GET /wallets/:id (no shards). */
|
|
26
|
+
export interface Wallet {
|
|
27
|
+
id: string;
|
|
28
|
+
address: string;
|
|
29
|
+
publicKey: string;
|
|
30
|
+
label: string;
|
|
31
|
+
status: WalletStatus;
|
|
32
|
+
createdAt: string;
|
|
33
|
+
fundedAt?: string | null;
|
|
34
|
+
}
|
|
35
|
+
export interface SendTransactionInput {
|
|
36
|
+
walletId: string;
|
|
37
|
+
agentShard: string;
|
|
38
|
+
to: string;
|
|
39
|
+
value: string;
|
|
40
|
+
data?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface SignMessageInput {
|
|
43
|
+
walletId: string;
|
|
44
|
+
agentShard: string;
|
|
45
|
+
message: string;
|
|
46
|
+
}
|
|
47
|
+
export interface ExportKeyInput {
|
|
48
|
+
walletId: string;
|
|
49
|
+
agentShard: string;
|
|
50
|
+
/**
|
|
51
|
+
* Optional. If provided, the server uses agentShard+backupShard for
|
|
52
|
+
* reconstruction without combining its own shard (server-less mode).
|
|
53
|
+
*/
|
|
54
|
+
backupShard?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface SweepInput {
|
|
57
|
+
walletId: string;
|
|
58
|
+
agentShard: string;
|
|
59
|
+
sweepTo: string;
|
|
60
|
+
}
|
|
61
|
+
export interface SentTransaction {
|
|
62
|
+
hash: string;
|
|
63
|
+
from: string;
|
|
64
|
+
to: string;
|
|
65
|
+
value: string;
|
|
66
|
+
walletType: WalletType;
|
|
67
|
+
explorer: string;
|
|
68
|
+
}
|
|
69
|
+
export interface BalanceResponse {
|
|
70
|
+
address: string;
|
|
71
|
+
native: {
|
|
72
|
+
wei: string;
|
|
73
|
+
formatted: string;
|
|
74
|
+
symbol: 'RITUAL';
|
|
75
|
+
};
|
|
76
|
+
ritualWallet: {
|
|
77
|
+
balance: string;
|
|
78
|
+
formatted: string;
|
|
79
|
+
lockUntil: string;
|
|
80
|
+
isLocked: boolean;
|
|
81
|
+
};
|
|
82
|
+
currentBlock: string;
|
|
83
|
+
}
|
|
84
|
+
export interface ExportedKey {
|
|
85
|
+
walletId: string;
|
|
86
|
+
address: string;
|
|
87
|
+
privateKey: string;
|
|
88
|
+
status: 'archived';
|
|
89
|
+
}
|
|
90
|
+
export type SubscriptionStatus = 'active' | 'paused' | 'disabled';
|
|
91
|
+
export type EventType = 'wallet.created' | 'wallet.imported' | 'wallet.frozen' | 'wallet.unfrozen' | 'wallet.archived' | 'wallet.funded' | 'wallet.swept' | 'tx.sent' | 'tx.received' | 'message.signed' | 'ritual.deposited' | 'key.exported' | 'webhook.test' | 'alert.spend_threshold' | 'alert.unusual_recipient' | 'alert.key_export_warning' | 'alert.balance_low';
|
|
92
|
+
export interface WebhookSubscription {
|
|
93
|
+
id: string;
|
|
94
|
+
url: string;
|
|
95
|
+
eventsFilter: (EventType | '*')[];
|
|
96
|
+
label: string;
|
|
97
|
+
status: SubscriptionStatus;
|
|
98
|
+
createdAt: string;
|
|
99
|
+
lastDeliveryAt: string | null;
|
|
100
|
+
consecutiveFailures: number;
|
|
101
|
+
}
|
|
102
|
+
/** POST /webhooks response — includes the one-time signing secret. */
|
|
103
|
+
export interface CreatedWebhook extends WebhookSubscription {
|
|
104
|
+
secret: string;
|
|
105
|
+
}
|
|
106
|
+
export interface CreateWebhookInput {
|
|
107
|
+
url: string;
|
|
108
|
+
events?: (EventType | '*')[];
|
|
109
|
+
label?: string;
|
|
110
|
+
}
|
|
111
|
+
export interface UpdateWebhookInput {
|
|
112
|
+
url?: string;
|
|
113
|
+
events?: (EventType | '*')[];
|
|
114
|
+
label?: string;
|
|
115
|
+
status?: 'active' | 'paused';
|
|
116
|
+
}
|
|
117
|
+
export interface DeliveryLogEntry {
|
|
118
|
+
id: string;
|
|
119
|
+
eventId: string;
|
|
120
|
+
status: 'pending' | 'delivered' | 'failed' | 'dead';
|
|
121
|
+
attempts: number;
|
|
122
|
+
url: string;
|
|
123
|
+
responseStatus: number | null;
|
|
124
|
+
lastError: string | null;
|
|
125
|
+
createdAt: string;
|
|
126
|
+
lastAttemptAt: string | null;
|
|
127
|
+
}
|
|
128
|
+
export interface BaseEvent {
|
|
129
|
+
id: string;
|
|
130
|
+
type: EventType;
|
|
131
|
+
timestamp: string;
|
|
132
|
+
walletId: string | null;
|
|
133
|
+
}
|
|
134
|
+
/** Each event's `data` shape is type-specific; we keep it loose at the SDK
|
|
135
|
+
* boundary so the wire format can evolve without breaking changes. Use
|
|
136
|
+
* the type tag to narrow. */
|
|
137
|
+
export interface RitkeyEvent<T = unknown> extends BaseEvent {
|
|
138
|
+
data: T;
|
|
139
|
+
}
|
|
140
|
+
export type AlertKind = 'spend_threshold' | 'unusual_recipient' | 'key_export_warning' | 'balance_low';
|
|
141
|
+
export type AlertSeverity = 'info' | 'warn' | 'critical';
|
|
142
|
+
export interface SpendThresholdConfig {
|
|
143
|
+
thresholdRitual: string;
|
|
144
|
+
}
|
|
145
|
+
export interface UnusualRecipientConfig {
|
|
146
|
+
whitelist: string[];
|
|
147
|
+
}
|
|
148
|
+
export interface KeyExportWarningConfig {
|
|
149
|
+
}
|
|
150
|
+
export interface BalanceLowConfig {
|
|
151
|
+
floorRitual: string;
|
|
152
|
+
}
|
|
153
|
+
export type AlertConfig = SpendThresholdConfig | UnusualRecipientConfig | KeyExportWarningConfig | BalanceLowConfig;
|
|
154
|
+
export interface AlertRule {
|
|
155
|
+
id: string;
|
|
156
|
+
walletId: string | null;
|
|
157
|
+
kind: AlertKind;
|
|
158
|
+
config: AlertConfig;
|
|
159
|
+
enabled: boolean;
|
|
160
|
+
severity: AlertSeverity;
|
|
161
|
+
label: string;
|
|
162
|
+
createdAt: string;
|
|
163
|
+
}
|
|
164
|
+
export interface CreateAlertRuleInput {
|
|
165
|
+
walletId: string;
|
|
166
|
+
kind: AlertKind;
|
|
167
|
+
config: AlertConfig;
|
|
168
|
+
severity?: AlertSeverity;
|
|
169
|
+
label?: string;
|
|
170
|
+
}
|
|
171
|
+
export interface UpdateAlertRuleInput {
|
|
172
|
+
enabled?: boolean;
|
|
173
|
+
severity?: AlertSeverity;
|
|
174
|
+
label?: string;
|
|
175
|
+
config?: AlertConfig;
|
|
176
|
+
}
|
|
177
|
+
export interface RitkeyClientConfig {
|
|
178
|
+
/** Base URL, e.g. https://ritkey.example.com */
|
|
179
|
+
baseUrl: string;
|
|
180
|
+
/** Bearer API key. Required unless your server is in OPEN_MODE. */
|
|
181
|
+
apiKey?: string;
|
|
182
|
+
/** Override fetch impl (for testing, custom retry, etc.) */
|
|
183
|
+
fetch?: typeof fetch;
|
|
184
|
+
/** Default per-request timeout in ms. Default: 30_000 */
|
|
185
|
+
timeoutMs?: number;
|
|
186
|
+
}
|
|
187
|
+
export declare class RitkeyError extends Error {
|
|
188
|
+
readonly status: number;
|
|
189
|
+
readonly code?: string;
|
|
190
|
+
readonly body: unknown;
|
|
191
|
+
constructor(status: number, message: string, body: unknown, code?: string);
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,MAAM,MAAM,U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W,CAAC;CACtB;AAMD,MAAM,WAAW,kBAAkB;IACjC,gDAAgD;IAChD,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;gBACX,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM;CAO1E"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for the Ritkey SDK.
|
|
3
|
+
*
|
|
4
|
+
* These mirror the wire format of the @ritkey/service HTTP API. Where the
|
|
5
|
+
* server returns extra `_notice` / `_security` documentation fields, the SDK
|
|
6
|
+
* forwards them so apps can show them to users on first wallet creation.
|
|
7
|
+
*/
|
|
8
|
+
export class RitkeyError extends Error {
|
|
9
|
+
status;
|
|
10
|
+
code;
|
|
11
|
+
body;
|
|
12
|
+
constructor(status, message, body, code) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = 'RitkeyError';
|
|
15
|
+
this.status = status;
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.body = body;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAwPH,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC3B,MAAM,CAAS;IACf,IAAI,CAAU;IACd,IAAI,CAAU;IACvB,YAAY,MAAc,EAAE,OAAe,EAAE,IAAa,EAAE,IAAa;QACvE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
|