@waiaas/wallet-sdk 2.12.0-rc.8 → 2.12.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/README.md +2 -2
- package/dist/channels/index.d.ts +0 -1
- package/dist/channels/index.d.ts.map +1 -1
- package/dist/channels/index.js +0 -1
- package/dist/channels/index.js.map +1 -1
- package/dist/channels/relay.d.ts +5 -7
- package/dist/channels/relay.d.ts.map +1 -1
- package/dist/channels/relay.js +6 -9
- package/dist/channels/relay.js.map +1 -1
- package/dist/index.d.ts +2 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -6
- package/dist/index.js.map +1 -1
- package/dist/parse-request.d.ts +4 -7
- package/dist/parse-request.d.ts.map +1 -1
- package/dist/parse-request.js +8 -76
- package/dist/parse-request.js.map +1 -1
- package/package.json +2 -2
- package/dist/channels/ntfy.d.ts +0 -66
- package/dist/channels/ntfy.d.ts.map +0 -1
- package/dist/channels/ntfy.js +0 -227
- package/dist/channels/ntfy.js.map +0 -1
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ graph LR
|
|
|
69
69
|
- **@waiaas/cli** — Command-line interface
|
|
70
70
|
- **@waiaas/admin** — Preact-based Admin Web UI
|
|
71
71
|
- **@waiaas/wallet-sdk** — Wallet Signing SDK for wallet app integration
|
|
72
|
-
- **@waiaas/push-relay** — Push Relay Server (
|
|
72
|
+
- **@waiaas/push-relay** — Push Relay Server (daemon → Pushwoosh/FCM native push)
|
|
73
73
|
- **@waiaas/skills** — Pre-built `.skill.md` instruction files for AI agents
|
|
74
74
|
|
|
75
75
|
See [Architecture](docs/architecture.md) for the full technical deep-dive.
|
|
@@ -179,7 +179,7 @@ Access the admin panel at `http://127.0.0.1:3100/admin` with your master passwor
|
|
|
179
179
|
- **Wallets** -- Create, manage, and monitor wallets across chains; RPC endpoints, balance monitoring, and WalletConnect settings
|
|
180
180
|
- **Sessions** -- Issue and revoke agent session tokens; session lifetime and rate limit settings
|
|
181
181
|
- **Policies** -- Configure 12 policy types with visual form editors; default deny and tier settings
|
|
182
|
-
- **Notifications** -- Channel status and delivery logs; Telegram, Discord,
|
|
182
|
+
- **Notifications** -- Channel status and delivery logs; Telegram, Discord, and Slack settings
|
|
183
183
|
- **Security** -- Kill Switch emergency controls, AutoStop protection rules, JWT rotation
|
|
184
184
|
- **System** -- API keys, display currency, price oracle, rate limits, log level, and daemon shutdown
|
|
185
185
|
|
package/dist/channels/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Channel exports for @waiaas/wallet-sdk.
|
|
3
3
|
*/
|
|
4
|
-
export { sendViaNtfy, subscribeToRequests, subscribeToNotifications, parseNotification, } from './ntfy.js';
|
|
5
4
|
export { sendViaTelegram } from './telegram.js';
|
|
6
5
|
export { sendViaRelay, registerDevice, unregisterDevice, getSubscriptionToken } from './relay.js';
|
|
7
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/channels/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/channels/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/channels/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Channel exports for @waiaas/wallet-sdk.
|
|
3
3
|
*/
|
|
4
|
-
export { sendViaNtfy, subscribeToRequests, subscribeToNotifications, parseNotification, } from './ntfy.js';
|
|
5
4
|
export { sendViaTelegram } from './telegram.js';
|
|
6
5
|
export { sendViaRelay, registerDevice, unregisterDevice, getSubscriptionToken } from './relay.js';
|
|
7
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/channels/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/channels/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/channels/relay.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Push Relay channel function for the WAIaaS Signing Protocol.
|
|
3
3
|
*
|
|
4
|
-
* Sends a SignResponse via the Push Relay server
|
|
5
|
-
* This allows wallet apps to only know the Push Relay URL, without needing
|
|
6
|
-
* direct access to the ntfy server.
|
|
4
|
+
* Sends a SignResponse via the Push Relay server.
|
|
7
5
|
*
|
|
8
6
|
* @see internal/design/73-signing-protocol-v1.md Section 7.4
|
|
9
7
|
*/
|
|
@@ -11,14 +9,14 @@ import type { SignResponse } from '@waiaas/core';
|
|
|
11
9
|
/**
|
|
12
10
|
* Send a SignResponse via Push Relay.
|
|
13
11
|
*
|
|
14
|
-
* Posts the response to the Push Relay's `/v1/sign-response` endpoint
|
|
15
|
-
*
|
|
12
|
+
* Posts the response to the Push Relay's `/v1/sign-response` endpoint.
|
|
13
|
+
* The relay stores it for the daemon to retrieve via long-polling.
|
|
16
14
|
*
|
|
17
15
|
* @param response - Validated SignResponse object
|
|
18
|
-
* @param responseTopic - ntfy response topic name (from SignRequest.responseChannel.responseTopic)
|
|
19
16
|
* @param pushRelayUrl - Push Relay server URL (e.g., "https://push-relay.example.com")
|
|
17
|
+
* @param apiKey - Push Relay API key (`X-API-Key`)
|
|
20
18
|
*/
|
|
21
|
-
export declare function sendViaRelay(response: SignResponse,
|
|
19
|
+
export declare function sendViaRelay(response: SignResponse, pushRelayUrl: string, apiKey: string): Promise<void>;
|
|
22
20
|
/**
|
|
23
21
|
* Register a device with the Push Relay server.
|
|
24
22
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relay.d.ts","sourceRoot":"","sources":["../../src/channels/relay.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"relay.d.ts","sourceRoot":"","sources":["../../src/channels/relay.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,YAAY,EACtB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAmBf;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CAClC,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,KAAK,GAAG,SAAS,CAAA;CAAE,GAC3E,OAAO,CAAC;IAAE,iBAAiB,EAAE,MAAM,CAAA;CAAE,CAAC,CAwBxC;AAED;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CACpC,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAaf;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,oBAAoB,CACxC,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAoBxB"}
|
package/dist/channels/relay.js
CHANGED
|
@@ -1,33 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Push Relay channel function for the WAIaaS Signing Protocol.
|
|
3
3
|
*
|
|
4
|
-
* Sends a SignResponse via the Push Relay server
|
|
5
|
-
* This allows wallet apps to only know the Push Relay URL, without needing
|
|
6
|
-
* direct access to the ntfy server.
|
|
4
|
+
* Sends a SignResponse via the Push Relay server.
|
|
7
5
|
*
|
|
8
6
|
* @see internal/design/73-signing-protocol-v1.md Section 7.4
|
|
9
7
|
*/
|
|
10
8
|
/**
|
|
11
9
|
* Send a SignResponse via Push Relay.
|
|
12
10
|
*
|
|
13
|
-
* Posts the response to the Push Relay's `/v1/sign-response` endpoint
|
|
14
|
-
*
|
|
11
|
+
* Posts the response to the Push Relay's `/v1/sign-response` endpoint.
|
|
12
|
+
* The relay stores it for the daemon to retrieve via long-polling.
|
|
15
13
|
*
|
|
16
14
|
* @param response - Validated SignResponse object
|
|
17
|
-
* @param responseTopic - ntfy response topic name (from SignRequest.responseChannel.responseTopic)
|
|
18
15
|
* @param pushRelayUrl - Push Relay server URL (e.g., "https://push-relay.example.com")
|
|
16
|
+
* @param apiKey - Push Relay API key (`X-API-Key`)
|
|
19
17
|
*/
|
|
20
|
-
export async function sendViaRelay(response,
|
|
18
|
+
export async function sendViaRelay(response, pushRelayUrl, apiKey) {
|
|
21
19
|
const url = `${pushRelayUrl.replace(/\/$/, '')}/v1/sign-response`;
|
|
22
20
|
const res = await fetch(url, {
|
|
23
21
|
method: 'POST',
|
|
24
|
-
headers: { 'Content-Type': 'application/json' },
|
|
22
|
+
headers: { 'Content-Type': 'application/json', 'X-API-Key': apiKey },
|
|
25
23
|
body: JSON.stringify({
|
|
26
24
|
requestId: response.requestId,
|
|
27
25
|
action: response.action,
|
|
28
26
|
...(response.signature !== undefined ? { signature: response.signature } : {}),
|
|
29
27
|
signerAddress: response.signerAddress,
|
|
30
|
-
responseTopic,
|
|
31
28
|
}),
|
|
32
29
|
});
|
|
33
30
|
if (!res.ok) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relay.js","sourceRoot":"","sources":["../../src/channels/relay.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"relay.js","sourceRoot":"","sources":["../../src/channels/relay.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,QAAsB,EACtB,YAAoB,EACpB,MAAc;IAEd,MAAM,GAAG,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,mBAAmB,CAAC;IAElE,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAC3B,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,EAAE;QACpE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,SAAS,EAAE,QAAQ,CAAC,SAAS;YAC7B,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,GAAG,CAAC,QAAQ,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9E,aAAa,EAAE,QAAQ,CAAC,aAAa;SACtC,CAAC;KACH,CAAC,CAAC;IAEH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,gDAAgD,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CACrE,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,YAAoB,EACpB,MAAc,EACd,IAA4E;IAE5E,MAAM,GAAG,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC;IAEzD,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAC3B,MAA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CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,kBAAkB,CAAC,SAAS,CAAC,qBAAqB,CAAC;IAE7G,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAC3B,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE;KACjC,CAAC,CAAC;IAEH,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,0DAA0D,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAC/E,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAmC,CAAC;IAClE,OAAO,IAAI,CAAC,kBAAkB,CAAC;AACjC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,15 +7,11 @@
|
|
|
7
7
|
* - parseSignRequest(url) - Extract SignRequest from universal link URL
|
|
8
8
|
* - buildSignResponse(requestId, action, signature?, signerAddress) - Create SignResponse
|
|
9
9
|
* - formatDisplayMessage(request) - Human-readable transaction summary
|
|
10
|
-
* -
|
|
11
|
-
* - sendViaRelay(response, topic, pushRelayUrl) - Send via Push Relay server
|
|
10
|
+
* - sendViaRelay(response, pushRelayUrl, apiKey) - Send via Push Relay server
|
|
12
11
|
* - registerDevice(pushRelayUrl, apiKey, opts) - Register device with Push Relay
|
|
13
12
|
* - unregisterDevice(pushRelayUrl, apiKey, pushToken) - Unregister device from Push Relay
|
|
14
13
|
* - getSubscriptionToken(pushRelayUrl, apiKey, pushToken) - Get subscription token for device
|
|
15
14
|
* - sendViaTelegram(response, botUsername) - Generate Telegram deeplink URL
|
|
16
|
-
* - subscribeToRequests(topic, callback, serverUrl?) - (deprecated) SSE subscription for sign requests
|
|
17
|
-
* - subscribeToNotifications(topic, callback, serverUrl?) - (deprecated) SSE subscription for notifications
|
|
18
|
-
* - parseNotification(data) - (deprecated) Decode and validate base64url NotificationMessage
|
|
19
15
|
*
|
|
20
16
|
* @see internal/design/73-signing-protocol-v1.md
|
|
21
17
|
* @see internal/design/74-wallet-sdk-daemon-components.md
|
|
@@ -23,7 +19,7 @@
|
|
|
23
19
|
export { parseSignRequest } from './parse-request.js';
|
|
24
20
|
export { buildSignResponse } from './build-response.js';
|
|
25
21
|
export { formatDisplayMessage } from './display.js';
|
|
26
|
-
export {
|
|
22
|
+
export { sendViaTelegram, sendViaRelay, registerDevice, unregisterDevice, getSubscriptionToken, } from './channels/index.js';
|
|
27
23
|
export { InvalidSignRequestUrlError, SignRequestExpiredError, SignRequestValidationError, } from './errors.js';
|
|
28
24
|
export type { SignRequest, SignResponse, WalletLinkConfig, NotificationMessage, } from '@waiaas/core';
|
|
29
25
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGpD,OAAO,EACL,eAAe,EACf,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,0BAA0B,EAC1B,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,aAAa,CAAC;AAGrB,YAAY,EACV,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -7,15 +7,11 @@
|
|
|
7
7
|
* - parseSignRequest(url) - Extract SignRequest from universal link URL
|
|
8
8
|
* - buildSignResponse(requestId, action, signature?, signerAddress) - Create SignResponse
|
|
9
9
|
* - formatDisplayMessage(request) - Human-readable transaction summary
|
|
10
|
-
* -
|
|
11
|
-
* - sendViaRelay(response, topic, pushRelayUrl) - Send via Push Relay server
|
|
10
|
+
* - sendViaRelay(response, pushRelayUrl, apiKey) - Send via Push Relay server
|
|
12
11
|
* - registerDevice(pushRelayUrl, apiKey, opts) - Register device with Push Relay
|
|
13
12
|
* - unregisterDevice(pushRelayUrl, apiKey, pushToken) - Unregister device from Push Relay
|
|
14
13
|
* - getSubscriptionToken(pushRelayUrl, apiKey, pushToken) - Get subscription token for device
|
|
15
14
|
* - sendViaTelegram(response, botUsername) - Generate Telegram deeplink URL
|
|
16
|
-
* - subscribeToRequests(topic, callback, serverUrl?) - (deprecated) SSE subscription for sign requests
|
|
17
|
-
* - subscribeToNotifications(topic, callback, serverUrl?) - (deprecated) SSE subscription for notifications
|
|
18
|
-
* - parseNotification(data) - (deprecated) Decode and validate base64url NotificationMessage
|
|
19
15
|
*
|
|
20
16
|
* @see internal/design/73-signing-protocol-v1.md
|
|
21
17
|
* @see internal/design/74-wallet-sdk-daemon-components.md
|
|
@@ -25,7 +21,7 @@ export { parseSignRequest } from './parse-request.js';
|
|
|
25
21
|
export { buildSignResponse } from './build-response.js';
|
|
26
22
|
export { formatDisplayMessage } from './display.js';
|
|
27
23
|
// Channel functions
|
|
28
|
-
export {
|
|
24
|
+
export { sendViaTelegram, sendViaRelay, registerDevice, unregisterDevice, getSubscriptionToken, } from './channels/index.js';
|
|
29
25
|
// Error classes
|
|
30
26
|
export { InvalidSignRequestUrlError, SignRequestExpiredError, SignRequestValidationError, } from './errors.js';
|
|
31
27
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,iBAAiB;AACjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,oBAAoB;AACpB,OAAO,EACL,eAAe,EACf,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAE7B,gBAAgB;AAChB,OAAO,EACL,0BAA0B,EAC1B,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,aAAa,CAAC"}
|
package/dist/parse-request.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* parseSignRequest - Extract SignRequest from a universal link URL.
|
|
3
3
|
*
|
|
4
|
-
* Supports
|
|
5
|
-
* 1. Inline data: URL contains ?data={base64url-encoded-SignRequest}
|
|
6
|
-
* 2. Remote fetch: URL contains ?requestId={uuid}&topic={topic}&serverUrl={url}
|
|
7
|
-
* (fetches from ntfy topic)
|
|
4
|
+
* Supports inline data mode: URL contains ?data={base64url-encoded-SignRequest}
|
|
8
5
|
*
|
|
9
6
|
* @see internal/design/74-wallet-sdk-daemon-components.md Section 2.1
|
|
10
7
|
*/
|
|
@@ -12,11 +9,11 @@ import type { SignRequest } from '@waiaas/core';
|
|
|
12
9
|
/**
|
|
13
10
|
* Parse a SignRequest from a universal link URL.
|
|
14
11
|
*
|
|
15
|
-
* @param url - Universal link URL with ?data=
|
|
16
|
-
* @returns SignRequest
|
|
12
|
+
* @param url - Universal link URL with ?data= parameter
|
|
13
|
+
* @returns Validated SignRequest
|
|
17
14
|
* @throws InvalidSignRequestUrlError - URL is invalid or missing parameters
|
|
18
15
|
* @throws SignRequestExpiredError - Request has expired
|
|
19
16
|
* @throws SignRequestValidationError - Decoded data fails Zod validation
|
|
20
17
|
*/
|
|
21
|
-
export declare function parseSignRequest(url: string): SignRequest
|
|
18
|
+
export declare function parseSignRequest(url: string): SignRequest;
|
|
22
19
|
//# sourceMappingURL=parse-request.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-request.d.ts","sourceRoot":"","sources":["../src/parse-request.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"parse-request.d.ts","sourceRoot":"","sources":["../src/parse-request.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AA6ChD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAgBzD"}
|
package/dist/parse-request.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* parseSignRequest - Extract SignRequest from a universal link URL.
|
|
3
3
|
*
|
|
4
|
-
* Supports
|
|
5
|
-
* 1. Inline data: URL contains ?data={base64url-encoded-SignRequest}
|
|
6
|
-
* 2. Remote fetch: URL contains ?requestId={uuid}&topic={topic}&serverUrl={url}
|
|
7
|
-
* (fetches from ntfy topic)
|
|
4
|
+
* Supports inline data mode: URL contains ?data={base64url-encoded-SignRequest}
|
|
8
5
|
*
|
|
9
6
|
* @see internal/design/74-wallet-sdk-daemon-components.md Section 2.1
|
|
10
7
|
*/
|
|
@@ -24,13 +21,7 @@ function assertNotExpired(request) {
|
|
|
24
21
|
* Decode inline data parameter (base64url -> JSON -> Zod validated SignRequest).
|
|
25
22
|
*/
|
|
26
23
|
function decodeInlineData(data) {
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
json = Buffer.from(data, 'base64url').toString('utf-8');
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
throw new InvalidSignRequestUrlError('Invalid base64url data parameter');
|
|
33
|
-
}
|
|
24
|
+
const json = Buffer.from(data, 'base64url').toString('utf-8');
|
|
34
25
|
let parsed;
|
|
35
26
|
try {
|
|
36
27
|
parsed = JSON.parse(json);
|
|
@@ -38,9 +29,10 @@ function decodeInlineData(data) {
|
|
|
38
29
|
catch {
|
|
39
30
|
throw new InvalidSignRequestUrlError('Invalid JSON in data parameter');
|
|
40
31
|
}
|
|
41
|
-
let request;
|
|
42
32
|
try {
|
|
43
|
-
request = SignRequestSchema.parse(parsed);
|
|
33
|
+
const request = SignRequestSchema.parse(parsed);
|
|
34
|
+
assertNotExpired(request);
|
|
35
|
+
return request;
|
|
44
36
|
}
|
|
45
37
|
catch (err) {
|
|
46
38
|
if (err instanceof ZodError) {
|
|
@@ -48,66 +40,12 @@ function decodeInlineData(data) {
|
|
|
48
40
|
}
|
|
49
41
|
throw err;
|
|
50
42
|
}
|
|
51
|
-
assertNotExpired(request);
|
|
52
|
-
return request;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Fetch a SignRequest from an ntfy topic by requestId.
|
|
56
|
-
*/
|
|
57
|
-
async function fetchSignRequestFromNtfy(requestId, topic, serverUrl) {
|
|
58
|
-
const url = `${serverUrl}/${topic}/json?poll=1&since=all`;
|
|
59
|
-
const res = await fetch(url);
|
|
60
|
-
if (!res.ok) {
|
|
61
|
-
throw new InvalidSignRequestUrlError(`Failed to fetch from ntfy: HTTP ${String(res.status)}`);
|
|
62
|
-
}
|
|
63
|
-
const text = await res.text();
|
|
64
|
-
// ntfy returns newline-delimited JSON messages
|
|
65
|
-
const lines = text.trim().split('\n');
|
|
66
|
-
for (const line of lines) {
|
|
67
|
-
if (!line.trim())
|
|
68
|
-
continue;
|
|
69
|
-
let msg;
|
|
70
|
-
try {
|
|
71
|
-
msg = JSON.parse(line);
|
|
72
|
-
}
|
|
73
|
-
catch {
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
if (!msg.message)
|
|
77
|
-
continue;
|
|
78
|
-
let json;
|
|
79
|
-
try {
|
|
80
|
-
json = Buffer.from(msg.message, 'base64url').toString('utf-8');
|
|
81
|
-
}
|
|
82
|
-
catch {
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
let parsed;
|
|
86
|
-
try {
|
|
87
|
-
parsed = JSON.parse(json);
|
|
88
|
-
}
|
|
89
|
-
catch {
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
let request;
|
|
93
|
-
try {
|
|
94
|
-
request = SignRequestSchema.parse(parsed);
|
|
95
|
-
}
|
|
96
|
-
catch {
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
if (request.requestId === requestId) {
|
|
100
|
-
assertNotExpired(request);
|
|
101
|
-
return request;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
throw new InvalidSignRequestUrlError(`Sign request ${requestId} not found in ntfy topic ${topic}`);
|
|
105
43
|
}
|
|
106
44
|
/**
|
|
107
45
|
* Parse a SignRequest from a universal link URL.
|
|
108
46
|
*
|
|
109
|
-
* @param url - Universal link URL with ?data=
|
|
110
|
-
* @returns SignRequest
|
|
47
|
+
* @param url - Universal link URL with ?data= parameter
|
|
48
|
+
* @returns Validated SignRequest
|
|
111
49
|
* @throws InvalidSignRequestUrlError - URL is invalid or missing parameters
|
|
112
50
|
* @throws SignRequestExpiredError - Request has expired
|
|
113
51
|
* @throws SignRequestValidationError - Decoded data fails Zod validation
|
|
@@ -124,12 +62,6 @@ export function parseSignRequest(url) {
|
|
|
124
62
|
if (data) {
|
|
125
63
|
return decodeInlineData(data);
|
|
126
64
|
}
|
|
127
|
-
|
|
128
|
-
if (requestId) {
|
|
129
|
-
const topic = parsed.searchParams.get('topic') ?? 'waiaas-sign-requests';
|
|
130
|
-
const serverUrl = parsed.searchParams.get('serverUrl') ?? 'https://ntfy.sh';
|
|
131
|
-
return fetchSignRequestFromNtfy(requestId, topic, serverUrl);
|
|
132
|
-
}
|
|
133
|
-
throw new InvalidSignRequestUrlError('URL must contain either "data" or "requestId" parameter');
|
|
65
|
+
throw new InvalidSignRequestUrlError('URL must contain a "data" parameter');
|
|
134
66
|
}
|
|
135
67
|
//# sourceMappingURL=parse-request.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-request.js","sourceRoot":"","sources":["../src/parse-request.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"parse-request.js","sourceRoot":"","sources":["../src/parse-request.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAE/B,OAAO,EACL,0BAA0B,EAC1B,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,SAAS,gBAAgB,CAAC,OAAoB;IAC5C,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC;IACxD,IAAI,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;QAC3B,MAAM,IAAI,uBAAuB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACvD,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,gBAAgB,CAAC,IAAY;IACpC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAE9D,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,0BAA0B,CAAC,gCAAgC,CAAC,CAAC;IACzE,CAAC;IAED,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,iBAAiB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAChD,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAC1B,OAAO,OAAO,CAAC;IACjB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,QAAQ,EAAE,CAAC;YAC5B,MAAM,IAAI,0BAA0B,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACpD,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,IAAI,MAAW,CAAC;IAChB,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,0BAA0B,CAAC,gBAAgB,GAAG,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC7C,IAAI,IAAI,EAAE,CAAC;QACT,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,MAAM,IAAI,0BAA0B,CAClC,qCAAqC,CACtC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@waiaas/wallet-sdk",
|
|
3
|
-
"version": "2.12.0
|
|
3
|
+
"version": "2.12.0",
|
|
4
4
|
"description": "WAIaaS Wallet Signing SDK - integrate wallet apps with WAIaaS signing protocol",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"zod": "^3.24.0",
|
|
36
|
-
"@waiaas/core": "2.12.0
|
|
36
|
+
"@waiaas/core": "2.12.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/node": "^25.2.3",
|
package/dist/channels/ntfy.d.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ntfy channel functions for the WAIaaS Signing Protocol.
|
|
3
|
-
*
|
|
4
|
-
* @deprecated All functions in this module are deprecated. Use Push Relay
|
|
5
|
-
* functions (sendViaRelay, registerDevice, etc.) from the relay channel instead.
|
|
6
|
-
* These will be removed in the next major version.
|
|
7
|
-
*
|
|
8
|
-
* @see internal/design/73-signing-protocol-v1.md Section 7.4
|
|
9
|
-
* @see internal/design/74-wallet-sdk-daemon-components.md Section 2.6
|
|
10
|
-
*/
|
|
11
|
-
import type { SignRequest, SignResponse, NotificationMessage } from '@waiaas/core';
|
|
12
|
-
/**
|
|
13
|
-
* Publish a SignResponse to an ntfy response topic.
|
|
14
|
-
*
|
|
15
|
-
* Encodes the response as base64url and POSTs it to the ntfy server.
|
|
16
|
-
*
|
|
17
|
-
* @deprecated Use Push Relay functions (sendViaRelay) instead. Will be removed in next major version.
|
|
18
|
-
* @param response - Validated SignResponse object
|
|
19
|
-
* @param responseTopic - ntfy topic name for responses
|
|
20
|
-
* @param serverUrl - ntfy server URL (defaults to https://ntfy.sh)
|
|
21
|
-
*/
|
|
22
|
-
export declare function sendViaNtfy(response: SignResponse, responseTopic: string, serverUrl?: string): Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Subscribe to sign requests via ntfy SSE stream.
|
|
25
|
-
*
|
|
26
|
-
* Listens for new messages on the specified ntfy topic and parses them
|
|
27
|
-
* as SignRequest objects. Valid, non-expired requests trigger the callback.
|
|
28
|
-
*
|
|
29
|
-
* @deprecated Use Push Relay device registration instead. Will be removed in next major version.
|
|
30
|
-
* @param topic - ntfy topic name for incoming sign requests
|
|
31
|
-
* @param callback - Function called for each valid SignRequest received
|
|
32
|
-
* @param serverUrl - ntfy server URL (defaults to https://ntfy.sh)
|
|
33
|
-
* @returns Object with unsubscribe() method to close the SSE connection
|
|
34
|
-
*/
|
|
35
|
-
export declare function subscribeToRequests(topic: string, callback: (request: SignRequest) => void, serverUrl?: string): {
|
|
36
|
-
unsubscribe: () => void;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Parse and validate a base64url-encoded NotificationMessage.
|
|
40
|
-
*
|
|
41
|
-
* Decodes the base64url string, parses JSON, and validates against
|
|
42
|
-
* NotificationMessageSchema.
|
|
43
|
-
*
|
|
44
|
-
* @deprecated Use Push Relay notification parsing instead. Will be removed in next major version.
|
|
45
|
-
* @param data - base64url-encoded NotificationMessage JSON string
|
|
46
|
-
* @returns Validated NotificationMessage object
|
|
47
|
-
* @throws Error if decoding, parsing, or validation fails
|
|
48
|
-
*/
|
|
49
|
-
export declare function parseNotification(data: string): NotificationMessage;
|
|
50
|
-
/**
|
|
51
|
-
* Subscribe to notification events via ntfy SSE stream.
|
|
52
|
-
*
|
|
53
|
-
* Listens for new messages on the specified ntfy topic and parses them
|
|
54
|
-
* as NotificationMessage objects via parseNotification().
|
|
55
|
-
* Valid messages trigger the callback.
|
|
56
|
-
*
|
|
57
|
-
* @deprecated Use Push Relay device registration instead. Will be removed in next major version.
|
|
58
|
-
* @param topic - ntfy topic name (e.g., 'waiaas-notify-trading-bot')
|
|
59
|
-
* @param callback - Function called for each valid NotificationMessage received
|
|
60
|
-
* @param serverUrl - ntfy server URL (defaults to https://ntfy.sh)
|
|
61
|
-
* @returns Object with unsubscribe() method to close the SSE connection
|
|
62
|
-
*/
|
|
63
|
-
export declare function subscribeToNotifications(topic: string, callback: (message: NotificationMessage) => void, serverUrl?: string): {
|
|
64
|
-
unsubscribe: () => void;
|
|
65
|
-
};
|
|
66
|
-
//# sourceMappingURL=ntfy.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ntfy.d.ts","sourceRoot":"","sources":["../../src/channels/ntfy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AA+BnF;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,YAAY,EACtB,aAAa,EAAE,MAAM,EACrB,SAAS,GAAE,MAA2B,GACrC,OAAO,CAAC,IAAI,CAAC,CAef;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,EACxC,SAAS,GAAE,MAA2B,GACrC;IAAE,WAAW,EAAE,MAAM,IAAI,CAAA;CAAE,CAmF7B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAInE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,EAChD,SAAS,GAAE,MAA2B,GACrC;IAAE,WAAW,EAAE,MAAM,IAAI,CAAA;CAAE,CAqE7B"}
|
package/dist/channels/ntfy.js
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ntfy channel functions for the WAIaaS Signing Protocol.
|
|
3
|
-
*
|
|
4
|
-
* @deprecated All functions in this module are deprecated. Use Push Relay
|
|
5
|
-
* functions (sendViaRelay, registerDevice, etc.) from the relay channel instead.
|
|
6
|
-
* These will be removed in the next major version.
|
|
7
|
-
*
|
|
8
|
-
* @see internal/design/73-signing-protocol-v1.md Section 7.4
|
|
9
|
-
* @see internal/design/74-wallet-sdk-daemon-components.md Section 2.6
|
|
10
|
-
*/
|
|
11
|
-
import { SignRequestSchema, NotificationMessageSchema } from '@waiaas/core';
|
|
12
|
-
const DEFAULT_SERVER_URL = 'https://ntfy.sh';
|
|
13
|
-
const MAX_RECONNECT_ATTEMPTS = 3;
|
|
14
|
-
const RECONNECT_DELAY_MS = 5_000;
|
|
15
|
-
/**
|
|
16
|
-
* Resolve the actual encoded message from an ntfy event.
|
|
17
|
-
* When payload exceeds ntfy's size limit, the message is stored as a file
|
|
18
|
-
* attachment and must be downloaded to recover the original request body.
|
|
19
|
-
*/
|
|
20
|
-
async function resolveMessage(event) {
|
|
21
|
-
if (event.attachment?.url) {
|
|
22
|
-
const res = await fetch(event.attachment.url);
|
|
23
|
-
if (!res.ok)
|
|
24
|
-
return null;
|
|
25
|
-
const body = (await res.json());
|
|
26
|
-
return typeof body.message === 'string' ? body.message : null;
|
|
27
|
-
}
|
|
28
|
-
return event.message ?? null;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Publish a SignResponse to an ntfy response topic.
|
|
32
|
-
*
|
|
33
|
-
* Encodes the response as base64url and POSTs it to the ntfy server.
|
|
34
|
-
*
|
|
35
|
-
* @deprecated Use Push Relay functions (sendViaRelay) instead. Will be removed in next major version.
|
|
36
|
-
* @param response - Validated SignResponse object
|
|
37
|
-
* @param responseTopic - ntfy topic name for responses
|
|
38
|
-
* @param serverUrl - ntfy server URL (defaults to https://ntfy.sh)
|
|
39
|
-
*/
|
|
40
|
-
export async function sendViaNtfy(response, responseTopic, serverUrl = DEFAULT_SERVER_URL) {
|
|
41
|
-
const json = JSON.stringify(response);
|
|
42
|
-
const encoded = Buffer.from(json, 'utf-8').toString('base64url');
|
|
43
|
-
const url = `${serverUrl}/${responseTopic}`;
|
|
44
|
-
const res = await fetch(url, {
|
|
45
|
-
method: 'POST',
|
|
46
|
-
body: encoded,
|
|
47
|
-
});
|
|
48
|
-
if (!res.ok) {
|
|
49
|
-
throw new Error(`Failed to send response to ntfy: HTTP ${String(res.status)}`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Subscribe to sign requests via ntfy SSE stream.
|
|
54
|
-
*
|
|
55
|
-
* Listens for new messages on the specified ntfy topic and parses them
|
|
56
|
-
* as SignRequest objects. Valid, non-expired requests trigger the callback.
|
|
57
|
-
*
|
|
58
|
-
* @deprecated Use Push Relay device registration instead. Will be removed in next major version.
|
|
59
|
-
* @param topic - ntfy topic name for incoming sign requests
|
|
60
|
-
* @param callback - Function called for each valid SignRequest received
|
|
61
|
-
* @param serverUrl - ntfy server URL (defaults to https://ntfy.sh)
|
|
62
|
-
* @returns Object with unsubscribe() method to close the SSE connection
|
|
63
|
-
*/
|
|
64
|
-
export function subscribeToRequests(topic, callback, serverUrl = DEFAULT_SERVER_URL) {
|
|
65
|
-
const abortController = new AbortController();
|
|
66
|
-
let reconnectAttempts = 0;
|
|
67
|
-
async function connect() {
|
|
68
|
-
if (abortController.signal.aborted)
|
|
69
|
-
return;
|
|
70
|
-
try {
|
|
71
|
-
const url = `${serverUrl}/${topic}/sse`;
|
|
72
|
-
const res = await fetch(url, {
|
|
73
|
-
signal: abortController.signal,
|
|
74
|
-
});
|
|
75
|
-
if (!res.ok || !res.body) {
|
|
76
|
-
throw new Error(`SSE connection failed: HTTP ${String(res.status)}`);
|
|
77
|
-
}
|
|
78
|
-
// Reset reconnect counter on successful connection
|
|
79
|
-
reconnectAttempts = 0;
|
|
80
|
-
const reader = res.body.getReader();
|
|
81
|
-
const decoder = new TextDecoder();
|
|
82
|
-
let buffer = '';
|
|
83
|
-
while (!abortController.signal.aborted) {
|
|
84
|
-
const { done, value } = await reader.read();
|
|
85
|
-
if (done)
|
|
86
|
-
break;
|
|
87
|
-
buffer += decoder.decode(value, { stream: true });
|
|
88
|
-
const lines = buffer.split('\n');
|
|
89
|
-
// Keep the last incomplete line in buffer
|
|
90
|
-
buffer = lines.pop() ?? '';
|
|
91
|
-
for (const line of lines) {
|
|
92
|
-
if (!line.startsWith('data: '))
|
|
93
|
-
continue;
|
|
94
|
-
const dataStr = line.slice(6).trim();
|
|
95
|
-
if (!dataStr)
|
|
96
|
-
continue;
|
|
97
|
-
try {
|
|
98
|
-
const event = JSON.parse(dataStr);
|
|
99
|
-
const message = await resolveMessage(event);
|
|
100
|
-
if (!message)
|
|
101
|
-
continue;
|
|
102
|
-
const json = Buffer.from(message, 'base64url').toString('utf-8');
|
|
103
|
-
const parsed = JSON.parse(json);
|
|
104
|
-
const request = SignRequestSchema.parse(parsed);
|
|
105
|
-
// Skip expired requests
|
|
106
|
-
const expiresAt = new Date(request.expiresAt).getTime();
|
|
107
|
-
if (expiresAt < Date.now()) {
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
callback(request);
|
|
111
|
-
}
|
|
112
|
-
catch {
|
|
113
|
-
// Ignore malformed messages
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
catch (_err) {
|
|
119
|
-
// Don't reconnect if explicitly aborted
|
|
120
|
-
if (abortController.signal.aborted)
|
|
121
|
-
return;
|
|
122
|
-
reconnectAttempts++;
|
|
123
|
-
if (reconnectAttempts <= MAX_RECONNECT_ATTEMPTS) {
|
|
124
|
-
await new Promise((resolve) => setTimeout(resolve, RECONNECT_DELAY_MS));
|
|
125
|
-
void connect();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
void connect();
|
|
130
|
-
return {
|
|
131
|
-
unsubscribe() {
|
|
132
|
-
abortController.abort();
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Parse and validate a base64url-encoded NotificationMessage.
|
|
138
|
-
*
|
|
139
|
-
* Decodes the base64url string, parses JSON, and validates against
|
|
140
|
-
* NotificationMessageSchema.
|
|
141
|
-
*
|
|
142
|
-
* @deprecated Use Push Relay notification parsing instead. Will be removed in next major version.
|
|
143
|
-
* @param data - base64url-encoded NotificationMessage JSON string
|
|
144
|
-
* @returns Validated NotificationMessage object
|
|
145
|
-
* @throws Error if decoding, parsing, or validation fails
|
|
146
|
-
*/
|
|
147
|
-
export function parseNotification(data) {
|
|
148
|
-
const json = Buffer.from(data, 'base64url').toString('utf-8');
|
|
149
|
-
const parsed = JSON.parse(json);
|
|
150
|
-
return NotificationMessageSchema.parse(parsed);
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Subscribe to notification events via ntfy SSE stream.
|
|
154
|
-
*
|
|
155
|
-
* Listens for new messages on the specified ntfy topic and parses them
|
|
156
|
-
* as NotificationMessage objects via parseNotification().
|
|
157
|
-
* Valid messages trigger the callback.
|
|
158
|
-
*
|
|
159
|
-
* @deprecated Use Push Relay device registration instead. Will be removed in next major version.
|
|
160
|
-
* @param topic - ntfy topic name (e.g., 'waiaas-notify-trading-bot')
|
|
161
|
-
* @param callback - Function called for each valid NotificationMessage received
|
|
162
|
-
* @param serverUrl - ntfy server URL (defaults to https://ntfy.sh)
|
|
163
|
-
* @returns Object with unsubscribe() method to close the SSE connection
|
|
164
|
-
*/
|
|
165
|
-
export function subscribeToNotifications(topic, callback, serverUrl = DEFAULT_SERVER_URL) {
|
|
166
|
-
const abortController = new AbortController();
|
|
167
|
-
let reconnectAttempts = 0;
|
|
168
|
-
async function connect() {
|
|
169
|
-
if (abortController.signal.aborted)
|
|
170
|
-
return;
|
|
171
|
-
try {
|
|
172
|
-
const url = `${serverUrl}/${topic}/sse`;
|
|
173
|
-
const res = await fetch(url, {
|
|
174
|
-
signal: abortController.signal,
|
|
175
|
-
});
|
|
176
|
-
if (!res.ok || !res.body) {
|
|
177
|
-
throw new Error(`SSE connection failed: HTTP ${String(res.status)}`);
|
|
178
|
-
}
|
|
179
|
-
reconnectAttempts = 0;
|
|
180
|
-
const reader = res.body.getReader();
|
|
181
|
-
const decoder = new TextDecoder();
|
|
182
|
-
let buffer = '';
|
|
183
|
-
while (!abortController.signal.aborted) {
|
|
184
|
-
const { done, value } = await reader.read();
|
|
185
|
-
if (done)
|
|
186
|
-
break;
|
|
187
|
-
buffer += decoder.decode(value, { stream: true });
|
|
188
|
-
const lines = buffer.split('\n');
|
|
189
|
-
buffer = lines.pop() ?? '';
|
|
190
|
-
for (const line of lines) {
|
|
191
|
-
if (!line.startsWith('data: '))
|
|
192
|
-
continue;
|
|
193
|
-
const dataStr = line.slice(6).trim();
|
|
194
|
-
if (!dataStr)
|
|
195
|
-
continue;
|
|
196
|
-
try {
|
|
197
|
-
const event = JSON.parse(dataStr);
|
|
198
|
-
const message = await resolveMessage(event);
|
|
199
|
-
if (!message)
|
|
200
|
-
continue;
|
|
201
|
-
const notification = parseNotification(message);
|
|
202
|
-
callback(notification);
|
|
203
|
-
}
|
|
204
|
-
catch {
|
|
205
|
-
// Ignore malformed messages
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
catch (_err) {
|
|
211
|
-
if (abortController.signal.aborted)
|
|
212
|
-
return;
|
|
213
|
-
reconnectAttempts++;
|
|
214
|
-
if (reconnectAttempts <= MAX_RECONNECT_ATTEMPTS) {
|
|
215
|
-
await new Promise((resolve) => setTimeout(resolve, RECONNECT_DELAY_MS));
|
|
216
|
-
void connect();
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
void connect();
|
|
221
|
-
return {
|
|
222
|
-
unsubscribe() {
|
|
223
|
-
abortController.abort();
|
|
224
|
-
},
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
//# sourceMappingURL=ntfy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ntfy.js","sourceRoot":"","sources":["../../src/channels/ntfy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;AAE5E,MAAM,kBAAkB,GAAG,iBAAiB,CAAC;AAC7C,MAAM,sBAAsB,GAAG,CAAC,CAAC;AACjC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAWjC;;;;GAIG;AACH,KAAK,UAAU,cAAc,CAAC,KAAgB;IAC5C,IAAI,KAAK,CAAC,UAAU,EAAE,GAAG,EAAE,CAA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