@bsv/expo-wallet-toolbox 0.17.0 → 0.19.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.
@@ -0,0 +1,208 @@
1
+ /**
2
+ * `@bsv/webrtpay` as the toolbox uses it. It is an optional peer dependency: a host that offers
3
+ * direct payments installs it (with react-native-webrtc), and every other host has none.
4
+ *
5
+ * So nothing in the toolbox imports it, not even for types. The package ships as TypeScript
6
+ * source, and a type import of a module a host does not have fails that host's type check. The
7
+ * shapes below are the slices the toolbox calls, written out by hand;
8
+ * `__tests__/directpay/webrtpayShape.test.ts` checks at type level that the real package fits
9
+ * them, so a release that changes one fails there rather than on a phone.
10
+ *
11
+ * The package is required lazily, inside a `try`, the way `services/vault/driver.ts` requires
12
+ * react-native-yubikey: Metro skips a missing module there because Expo's Metro config turns on
13
+ * `allowOptionalDependencies`, and requiring it only on first use keeps the barrel import free
14
+ * of it. `loadWebRTPay()` is null when it is not installed (or will not load).
15
+ */
16
+ import type { WalletInterface } from '@bsv/sdk'
17
+ import type { IceServer } from './settings'
18
+
19
+ /** The slice of a BRC-100 wallet `@bsv/webrtpay` uses (its `WalletLike`). */
20
+ export type WebRTPayWallet = Pick<
21
+ WalletInterface,
22
+ | 'getPublicKey'
23
+ | 'createSignature'
24
+ | 'verifySignature'
25
+ | 'encrypt'
26
+ | 'decrypt'
27
+ | 'createHmac'
28
+ | 'verifyHmac'
29
+ | 'internalizeAction'
30
+ >
31
+
32
+ /** `WebRTPayError`: `code` says what failed; `reason` is a refusal's reason (`busy`, …). */
33
+ export interface WebRTPayErrorLike extends Error {
34
+ readonly code: string
35
+ readonly reason?: string
36
+ }
37
+
38
+ /** A payment token as it goes over the link (PeerPay's `PaymentToken`). */
39
+ export interface DirectPaymentToken {
40
+ customInstructions: { derivationPrefix: string; derivationSuffix: string }
41
+ transaction: number[]
42
+ amount: number
43
+ outputIndex?: number
44
+ }
45
+
46
+ /** A payment from an authenticated peer: `sender` is the peer's proven identity key. */
47
+ export interface IncomingDirectPayment {
48
+ messageId: string
49
+ sender: string
50
+ token: DirectPaymentToken
51
+ outputIndex?: number
52
+ }
53
+
54
+ /** What this wallet answers a payment with: in the wallet, kept for a retry, or refused. */
55
+ export type DirectPaymentDecision = 'accepted' | 'received' | { status: 'rejected'; reason: string }
56
+
57
+ /** The payee's answer to a payment. */
58
+ export interface DirectPaymentAck {
59
+ status: 'accepted' | 'received' | 'rejected'
60
+ txid?: string
61
+ reason?: string
62
+ }
63
+
64
+ /** An authenticated link to one peer. */
65
+ export interface DirectPeer {
66
+ readonly peerIdentityKey: string
67
+ readonly isOpen: boolean
68
+ close(): void
69
+ }
70
+
71
+ export interface DirectReceiveHandlers {
72
+ onPayment(p: IncomingDirectPayment, ctx: { note?: string; txid: string }): Promise<DirectPaymentDecision>
73
+ onError?(e: unknown): void
74
+ }
75
+
76
+ /** `DirectPayClient`: dials, sends, and receives while listening. */
77
+ export interface DirectPayClientLike {
78
+ startReceiving(h: DirectReceiveHandlers): Promise<void>
79
+ stopReceiving(): Promise<void>
80
+ connect(recipient: string, o?: { signal?: AbortSignal }): Promise<DirectPeer>
81
+ sendPayment(peer: DirectPeer, token: DirectPaymentToken, o?: { note?: string }): Promise<DirectPaymentAck>
82
+ close(): Promise<void>
83
+ }
84
+
85
+ /** An encrypted signal as a carrier moves it; the toolbox never opens one. */
86
+ export interface SignalEnvelopeLike {
87
+ v: 1
88
+ sid: string
89
+ ciphertext: string
90
+ }
91
+
92
+ /** A carrier for signals: the message box or a relay. */
93
+ export interface SignalerLike {
94
+ send(to: string, e: SignalEnvelopeLike): Promise<void>
95
+ listen(fn: (from: string, e: SignalEnvelopeLike) => void): Promise<() => Promise<void>>
96
+ }
97
+
98
+ /** `connecting` while it opens, `online` once the relay accepted this wallet, else `offline`. */
99
+ export type RelayState = 'connecting' | 'online' | 'offline'
100
+
101
+ export interface RelaySignalerLike extends SignalerLike {
102
+ close(): Promise<void>
103
+ /** The relay's short-lived TURN servers, for `iceServersProvider`. */
104
+ turnProvider(): () => Promise<IceServer[]>
105
+ }
106
+
107
+ /**
108
+ * The message box client as the signaler uses it. message-box-client's `PeerPayClient` is one
109
+ * (pinned at type level in `__tests__/directpay/webrtpayShape.test.ts`); its live websocket
110
+ * calls make the signaler fast enough for the dial's presence window.
111
+ */
112
+ export interface MessageBoxLike {
113
+ sendMessage(a: { recipient: string; messageBox: string; body: string }, overrideHost?: string): Promise<unknown>
114
+ listMessages(a: {
115
+ messageBox: string
116
+ host?: string
117
+ limit?: number
118
+ pageSize?: number
119
+ maxPages?: number
120
+ acceptPayments?: boolean
121
+ }): Promise<{ messageId: string; sender: string; body: string | Record<string, unknown> }[]>
122
+ acknowledgeMessage(a: { messageIds: string[]; host?: string }): Promise<unknown>
123
+ resolveHostForRecipient?(identityKey: string): Promise<string>
124
+ sendLiveMessage?(a: { recipient: string; messageBox: string; body: string }, overrideHost?: string): Promise<unknown>
125
+ listenForLiveMessages?(a: {
126
+ messageBox: string
127
+ overrideHost?: string
128
+ onMessage: (m: { messageId: string; sender: string; body: string | Record<string, unknown> }) => void
129
+ }): Promise<void>
130
+ joinRoom?(messageBox: string, overrideHost?: string): Promise<void>
131
+ leaveRoom?(messageBox: string): Promise<void>
132
+ }
133
+
134
+ export interface DirectPayClientOptions {
135
+ wallet: WebRTPayWallet
136
+ originator?: string
137
+ signaler?: SignalerLike
138
+ rtc?: {
139
+ iceServers?: IceServer[]
140
+ /**
141
+ * The host's constructor (react-native-webrtc's on a phone). `any` because the package
142
+ * wants the DOM's `typeof RTCPeerConnection`, and the toolbox has no WebRTC types.
143
+ */
144
+ RTCPeerConnection?: any
145
+ }
146
+ iceServersProvider?: () => Promise<IceServer[]>
147
+ onIceServersProviderError?: (e: unknown) => void
148
+ chain?: string
149
+ timeouts?: { connectMs?: number; ackMs?: number; presenceMs?: number; dialMs?: number }
150
+ }
151
+
152
+ export interface RelaySignalerOptions {
153
+ url: string
154
+ wallet: Pick<WebRTPayWallet, 'getPublicKey' | 'createSignature'>
155
+ originator?: string
156
+ onStateChange?: (state: RelayState, error?: WebRTPayErrorLike) => void
157
+ }
158
+
159
+ /** A seen store: which payments were already taken (`paymentKey`). */
160
+ export interface DirectPaySeenStore {
161
+ has(key: string): boolean | Promise<boolean>
162
+ add(key: string): void | Promise<void>
163
+ }
164
+
165
+ /** The module, as far as the toolbox calls it. */
166
+ export interface WebRTPayModule {
167
+ DirectPayClient: new (o: DirectPayClientOptions) => DirectPayClientLike
168
+ MessageBoxSignaler: new (client: MessageBoxLike, o?: { messageBox?: string; host?: string }) => SignalerLike
169
+ RelaySignaler: new (o: RelaySignalerOptions) => RelaySignalerLike
170
+ WebRTPayError: new (
171
+ code: 'rejected' | 'invalid_payment',
172
+ message?: string,
173
+ o?: { cause?: unknown; reason?: string }
174
+ ) => WebRTPayErrorLike
175
+ acceptDirectPayment(
176
+ wallet: WebRTPayWallet,
177
+ p: IncomingDirectPayment,
178
+ o?: { originator?: string; seen?: DirectPaySeenStore; labels?: string[]; description?: string }
179
+ ): Promise<{ txid: string; status: 'accepted' | 'duplicate' }>
180
+ validatePaymentToken(token: DirectPaymentToken, note?: string): void
181
+ readonly MAX_DIRECT_TRANSACTION_BYTES: number
182
+ }
183
+
184
+ let loaded: WebRTPayModule | null | undefined
185
+
186
+ /** `@bsv/webrtpay`, or null when this host does not have it. Required once, on first use. */
187
+ export function loadWebRTPay(): WebRTPayModule | null {
188
+ if (loaded !== undefined) return loaded
189
+ try {
190
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
191
+ loaded = require('@bsv/webrtpay') as WebRTPayModule
192
+ } catch (e) {
193
+ console.warn('[directpay] @bsv/webrtpay is not available:', e instanceof Error ? e.message : String(e))
194
+ loaded = null
195
+ }
196
+ return loaded
197
+ }
198
+
199
+ /** Replaces what {@link loadWebRTPay} returns; `undefined` loads the package again. Tests only. */
200
+ export function setWebRTPayForTests(m: WebRTPayModule | null | undefined): void {
201
+ loaded = m
202
+ }
203
+
204
+ /** Whether `e` is a `WebRTPayError` of `mod`, or one that lost its prototype on the way (duck-typed). */
205
+ export function isWebRTPayError(mod: Pick<WebRTPayModule, 'WebRTPayError'>, e: unknown): e is WebRTPayErrorLike {
206
+ if (e instanceof mod.WebRTPayError) return true
207
+ return typeof e === 'object' && e !== null && (e as { name?: unknown }).name === 'WebRTPayError'
208
+ }
@@ -1237,7 +1237,12 @@ const resources = {
1237
1237
  direct_pay_failed_maybe_sent:
1238
1238
  'Your payment to {{name}} may already have been sent. Check Activity before paying again.',
1239
1239
  direct_pay_failed_not_sent: 'The payment could not be sent. Nothing was spent.',
1240
- direct_pay_failed_no_message_box: 'Connect your message box in Settings to pay a wallet identity.'
1240
+ direct_pay_failed_no_message_box: 'Connect your message box in Settings to pay a wallet identity.',
1241
+ direct_pay_fallback_title: 'Not online right now',
1242
+ direct_pay_fallback_send: 'Send to message box',
1243
+ direct_pay_sent_live: 'Paid live: it\'s already in their wallet.',
1244
+ direct_pay_kept_needs_attention:
1245
+ 'A direct payment of {{amount}} sats from {{name}} needs attention: your wallet could not add it. It stays on this device.'
1241
1246
  }
1242
1247
  },
1243
1248
  zh: {
@@ -2279,7 +2284,11 @@ const resources = {
2279
2284
  direct_pay_failed_cancelled: '已取消。未花费任何款项。',
2280
2285
  direct_pay_failed_maybe_sent: '你向 {{name}} 的付款可能已经发出。再次付款前,请先查看“活动”。',
2281
2286
  direct_pay_failed_not_sent: '无法发送付款。未花费任何款项。',
2282
- direct_pay_failed_no_message_box: '请在设置中连接消息箱,以便向钱包身份付款。'
2287
+ direct_pay_failed_no_message_box: '请在设置中连接消息箱,以便向钱包身份付款。',
2288
+ direct_pay_fallback_title: '对方当前不在线',
2289
+ direct_pay_fallback_send: '发送到消息箱',
2290
+ direct_pay_sent_live: '已实时付款:款项已到对方钱包。',
2291
+ direct_pay_kept_needs_attention: '来自 {{name}} 的 {{amount}} sats 直接付款需要处理:你的钱包无法添加它。它仍保存在此设备上。'
2283
2292
  }
2284
2293
  },
2285
2294
  hi: {
@@ -3400,7 +3409,12 @@ const resources = {
3400
3409
  '{{name}} को आपका भुगतान शायद पहले ही भेजा जा चुका है। दोबारा भुगतान करने से पहले गतिविधि देखें।',
3401
3410
  direct_pay_failed_not_sent: 'भुगतान भेजा नहीं जा सका। कुछ भी खर्च नहीं हुआ।',
3402
3411
  direct_pay_failed_no_message_box:
3403
- 'किसी वॉलेट आइडेंटिटी को भुगतान करने के लिए सेटिंग्स में अपना मैसेज बॉक्स जोड़ें।'
3412
+ 'किसी वॉलेट आइडेंटिटी को भुगतान करने के लिए सेटिंग्स में अपना मैसेज बॉक्स जोड़ें।',
3413
+ direct_pay_fallback_title: 'अभी ऑनलाइन नहीं',
3414
+ direct_pay_fallback_send: 'मैसेज बॉक्स में भेजें',
3415
+ direct_pay_sent_live: 'लाइव भुगतान हो गया: यह पहले से उनके वॉलेट में है।',
3416
+ direct_pay_kept_needs_attention:
3417
+ '{{name}} से {{amount}} sats के सीधे भुगतान पर ध्यान देना ज़रूरी है: आपका वॉलेट इसे जोड़ नहीं सका। यह इसी डिवाइस पर रखा है।'
3404
3418
  }
3405
3419
  },
3406
3420
  es: {
@@ -4538,7 +4552,12 @@ const resources = {
4538
4552
  'Es posible que tu pago a {{name}} ya se haya enviado. Revisa Actividad antes de volver a pagar.',
4539
4553
  direct_pay_failed_not_sent: 'No se pudo enviar el pago. No se gastó nada.',
4540
4554
  direct_pay_failed_no_message_box:
4541
- 'Conecta tu buzón de mensajes en Ajustes para pagar a una identidad de billetera.'
4555
+ 'Conecta tu buzón de mensajes en Ajustes para pagar a una identidad de billetera.',
4556
+ direct_pay_fallback_title: 'No está en línea ahora',
4557
+ direct_pay_fallback_send: 'Enviar al buzón de mensajes',
4558
+ direct_pay_sent_live: 'Pagado en vivo: ya está en su billetera.',
4559
+ direct_pay_kept_needs_attention:
4560
+ 'Un pago directo de {{amount}} sats de {{name}} necesita atención: tu billetera no pudo añadirlo. Se conserva en este dispositivo.'
4542
4561
  }
4543
4562
  },
4544
4563
  fr: {
@@ -5690,7 +5709,12 @@ const resources = {
5690
5709
  'Votre paiement à {{name}} a peut-être déjà été envoyé. Consultez Activité avant de payer à nouveau.',
5691
5710
  direct_pay_failed_not_sent: "Le paiement n'a pas pu être envoyé. Rien n'a été dépensé.",
5692
5711
  direct_pay_failed_no_message_box:
5693
- 'Connectez votre boîte aux lettres dans les réglages pour payer une identité de portefeuille.'
5712
+ 'Connectez votre boîte aux lettres dans les réglages pour payer une identité de portefeuille.',
5713
+ direct_pay_fallback_title: 'Pas en ligne pour le moment',
5714
+ direct_pay_fallback_send: 'Envoyer à la boîte aux lettres',
5715
+ direct_pay_sent_live: 'Payé en direct : c\'est déjà dans son portefeuille.',
5716
+ direct_pay_kept_needs_attention:
5717
+ "Un paiement direct de {{amount}} sats de {{name}} demande votre attention : votre portefeuille n'a pas pu l'ajouter. Il reste sur cet appareil."
5694
5718
  }
5695
5719
  },
5696
5720
  ar: {
@@ -6768,7 +6792,12 @@ const resources = {
6768
6792
  direct_pay_failed_cancelled: 'تم الإلغاء. لم يتم إنفاق أي مبلغ.',
6769
6793
  direct_pay_failed_maybe_sent: 'ربما تم إرسال دفعتك إلى {{name}} بالفعل. تحقق من النشاط قبل الدفع مرة أخرى.',
6770
6794
  direct_pay_failed_not_sent: 'تعذّر إرسال الدفعة. لم يتم إنفاق أي مبلغ.',
6771
- direct_pay_failed_no_message_box: 'اربط صندوق رسائلك من الإعدادات للدفع إلى هوية محفظة.'
6795
+ direct_pay_failed_no_message_box: 'اربط صندوق رسائلك من الإعدادات للدفع إلى هوية محفظة.',
6796
+ direct_pay_fallback_title: 'غير متصل الآن',
6797
+ direct_pay_fallback_send: 'أرسل إلى صندوق الرسائل',
6798
+ direct_pay_sent_live: 'تم الدفع مباشرة: المبلغ في محفظته بالفعل.',
6799
+ direct_pay_kept_needs_attention:
6800
+ 'دفعة مباشرة بقيمة {{amount}} sats من {{name}} تحتاج إلى انتباهك: لم تتمكن محفظتك من إضافتها. تبقى محفوظة على هذا الجهاز.'
6772
6801
  }
6773
6802
  },
6774
6803
  pt: {
@@ -7905,7 +7934,12 @@ const resources = {
7905
7934
  'Seu pagamento para {{name}} pode já ter sido enviado. Confira Atividade antes de pagar novamente.',
7906
7935
  direct_pay_failed_not_sent: 'Não foi possível enviar o pagamento. Nada foi gasto.',
7907
7936
  direct_pay_failed_no_message_box:
7908
- 'Conecte sua caixa de mensagens em Configurações para pagar uma identidade de carteira.'
7937
+ 'Conecte sua caixa de mensagens em Configurações para pagar uma identidade de carteira.',
7938
+ direct_pay_fallback_title: 'Não está online agora',
7939
+ direct_pay_fallback_send: 'Enviar para a caixa de mensagens',
7940
+ direct_pay_sent_live: 'Pago ao vivo: já está na carteira da pessoa.',
7941
+ direct_pay_kept_needs_attention:
7942
+ 'Um pagamento direto de {{amount}} sats de {{name}} precisa de atenção: sua carteira não conseguiu adicioná-lo. Ele continua neste dispositivo.'
7909
7943
  }
7910
7944
  },
7911
7945
  bn: {
@@ -9020,7 +9054,12 @@ const resources = {
9020
9054
  direct_pay_failed_maybe_sent:
9021
9055
  '{{name}}-এর কাছে আপনার পেমেন্ট হয়তো ইতিমধ্যে পাঠানো হয়ে গেছে। আবার পেমেন্ট করার আগে কার্যকলাপ দেখুন।',
9022
9056
  direct_pay_failed_not_sent: 'পেমেন্ট পাঠানো যায়নি। কিছুই খরচ হয়নি।',
9023
- direct_pay_failed_no_message_box: 'ওয়ালেট আইডেন্টিটিকে পেমেন্ট করতে সেটিংসে আপনার মেসেজ বক্স যুক্ত করুন।'
9057
+ direct_pay_failed_no_message_box: 'ওয়ালেট আইডেন্টিটিকে পেমেন্ট করতে সেটিংসে আপনার মেসেজ বক্স যুক্ত করুন।',
9058
+ direct_pay_fallback_title: 'এখন অনলাইনে নেই',
9059
+ direct_pay_fallback_send: 'মেসেজ বক্সে পাঠান',
9060
+ direct_pay_sent_live: 'সরাসরি পেমেন্ট হয়েছে: এটি ইতিমধ্যে তাদের ওয়ালেটে আছে।',
9061
+ direct_pay_kept_needs_attention:
9062
+ '{{name}}-এর কাছ থেকে {{amount}} sats-এর একটি সরাসরি পেমেন্টে মনোযোগ প্রয়োজন: আপনার ওয়ালেট এটি যোগ করতে পারেনি। এটি এই ডিভাইসেই রাখা আছে।'
9024
9063
  }
9025
9064
  },
9026
9065
  ru: {
@@ -10153,7 +10192,12 @@ const resources = {
10153
10192
  'Ваш платёж для {{name}}, возможно, уже отправлен. Проверьте «Активность», прежде чем платить снова.',
10154
10193
  direct_pay_failed_not_sent: 'Не удалось отправить платёж. Ничего не потрачено.',
10155
10194
  direct_pay_failed_no_message_box:
10156
- 'Подключите почтовый ящик в настройках, чтобы платить по идентификатору кошелька.'
10195
+ 'Подключите почтовый ящик в настройках, чтобы платить по идентификатору кошелька.',
10196
+ direct_pay_fallback_title: 'Сейчас не в сети',
10197
+ direct_pay_fallback_send: 'Отправить в почтовый ящик',
10198
+ direct_pay_sent_live: 'Оплачено напрямую: деньги уже в кошельке получателя.',
10199
+ direct_pay_kept_needs_attention:
10200
+ 'Прямой платёж на {{amount}} sats от {{name}} требует внимания: кошелёк не смог его добавить. Он сохранён на этом устройстве.'
10157
10201
  }
10158
10202
  },
10159
10203
  id: {
@@ -11283,7 +11327,12 @@ const resources = {
11283
11327
  direct_pay_failed_maybe_sent:
11284
11328
  'Pembayaran Anda ke {{name}} mungkin sudah terkirim. Periksa Aktivitas sebelum membayar lagi.',
11285
11329
  direct_pay_failed_not_sent: 'Pembayaran tidak dapat dikirim. Tidak ada dana yang terpakai.',
11286
- direct_pay_failed_no_message_box: 'Hubungkan kotak pesan Anda di Pengaturan untuk membayar identitas dompet.'
11330
+ direct_pay_failed_no_message_box: 'Hubungkan kotak pesan Anda di Pengaturan untuk membayar identitas dompet.',
11331
+ direct_pay_fallback_title: 'Sedang tidak online',
11332
+ direct_pay_fallback_send: 'Kirim ke kotak pesan',
11333
+ direct_pay_sent_live: 'Dibayar langsung: sudah masuk ke dompet mereka.',
11334
+ direct_pay_kept_needs_attention:
11335
+ 'Pembayaran langsung {{amount}} sats dari {{name}} perlu perhatian: dompet Anda tidak dapat menambahkannya. Pembayaran ini tetap tersimpan di perangkat ini.'
11287
11336
  }
11288
11337
  },
11289
11338
  ja: {
@@ -12412,7 +12461,11 @@ const resources = {
12412
12461
  direct_pay_failed_maybe_sent:
12413
12462
  '{{name}}への支払いはすでに送信されている可能性があります。もう一度支払う前に、アクティビティを確認してください。',
12414
12463
  direct_pay_failed_not_sent: '支払いを送信できませんでした。何も使われていません。',
12415
- direct_pay_failed_no_message_box: 'ウォレットIDに支払うには、設定でメッセージボックスを接続してください。'
12464
+ direct_pay_failed_no_message_box: 'ウォレットIDに支払うには、設定でメッセージボックスを接続してください。',
12465
+ direct_pay_fallback_title: '現在オンラインではありません',
12466
+ direct_pay_fallback_send: 'メッセージボックスに送る',
12467
+ direct_pay_sent_live: 'ライブで支払い済み:すでに相手のウォレットに入っています。',
12468
+ direct_pay_kept_needs_attention: '{{name}} からの {{amount}} sats のダイレクト支払いに対応が必要です。ウォレットに追加できませんでした。この端末に保存されています。'
12416
12469
  }
12417
12470
  },
12418
12471
  pl: {
@@ -13568,7 +13621,12 @@ const resources = {
13568
13621
  'Twoja płatność dla {{name}} mogła już zostać wysłana. Sprawdź Aktywność, zanim zapłacisz ponownie.',
13569
13622
  direct_pay_failed_not_sent: 'Nie udało się wysłać płatności. Nic nie wydano.',
13570
13623
  direct_pay_failed_no_message_box:
13571
- 'Połącz swoją skrzynkę wiadomości w ustawieniach, aby płacić tożsamości portfela.'
13624
+ 'Połącz swoją skrzynkę wiadomości w ustawieniach, aby płacić tożsamości portfela.',
13625
+ direct_pay_fallback_title: 'Teraz nie jest online',
13626
+ direct_pay_fallback_send: 'Wyślij do skrzynki wiadomości',
13627
+ direct_pay_sent_live: 'Zapłacono na żywo: środki są już w jego portfelu.',
13628
+ direct_pay_kept_needs_attention:
13629
+ 'Płatność bezpośrednia {{amount}} sats od {{name}} wymaga uwagi: portfel nie mógł jej dodać. Pozostaje na tym urządzeniu.'
13572
13630
  }
13573
13631
  }
13574
13632
  }
package/core/index.ts CHANGED
@@ -122,9 +122,14 @@ export * from './localpay/nearbyPermissions'
122
122
  // callers need to tell an AckError (radio failure → fountain) from a decline.
123
123
  export { AckError, QrHandoffRequired, type Ack, type LocalPaymentTransport, type ReceivedFrame } from './localpay/types'
124
124
  export { selectTransport, fallbackRadio, failedBeforeConnect } from './localpay/transport/select'
125
- // Direct (push) payments: settings, pay flow and status, as pure functions. The WebRTC
126
- // manager and the screens that use them are separate changes.
125
+ // Direct (push) payments: settings, pay flow and status as pure functions, and the
126
+ // @bsv/webrtpay shapes with its lazy loader. The screens that use them are a separate change.
127
127
  export * from './directpay'
128
+ // The runtime half of direct payments: see the note in './directpay/index'.
129
+ export * from './directpay/deviceStore'
130
+ export * from './directpay/receive'
131
+ export * from './directpay/DirectPayManager'
132
+ export * from './directpay/DirectPayProvider'
128
133
  export * from './peerpay/outbox'
129
134
  export * from './peerpay/control'
130
135
  export * from './peerpay/handleResendRequests'
@@ -266,6 +271,7 @@ export * from './pay/patp'
266
271
  export * from './pay/counterparty'
267
272
  export * from './pay/rails/address'
268
273
  export * from './pay/rails/handle'
274
+ export * from './pay/rails/direct'
269
275
  // nearby.ts is a pure re-export barrel over localpay/* (already exported above)
270
276
  // and @bsv/air-gap; only its genuinely new names are re-exported here by hand —
271
277
  // a blanket `export *` would collide (TS2308) with the localpay/offline exports
@@ -7,16 +7,8 @@
7
7
  */
8
8
  import { Beef } from '@bsv/sdk'
9
9
  import { type IncomingPayment, type PeerPayClient } from '@bsv/message-box-client'
10
- import {
11
- isPaymentTokenShape,
12
- listDamagedInboxMessages,
13
- type DamagedInboxMessage
14
- } from './damagedInbox'
15
- import {
16
- autoAcceptInbox,
17
- needsAttention,
18
- type InboxAttempt
19
- } from './rails/handle'
10
+ import { isPaymentTokenShape, listDamagedInboxMessages, type DamagedInboxMessage } from './damagedInbox'
11
+ import { autoAcceptInbox, needsAttention, type CreditOutcome, type InboxAttempt } from './rails/handle'
20
12
  import type { CreditFailureKind } from './creditErrors'
21
13
  import { sendControlMessage } from '../peerpay/control'
22
14
  import { loadInboxAttempts, saveInboxAttempts } from '../peerpay/inboxAttempts'
@@ -144,7 +136,7 @@ async function runCreditInbox(args: {
144
136
  storage?: StorageLike
145
137
  force?: string[]
146
138
  classify?: (e: unknown) => CreditFailureKind
147
- accept: (payment: IncomingPayment) => Promise<void>
139
+ accept: (payment: IncomingPayment) => Promise<void | CreditOutcome>
148
140
  }): Promise<CreditInboxResult> {
149
141
  const { client, messageBoxUrl, storage, force, classify, accept } = args
150
142
  const raw = await listRawInbox(client, messageBoxUrl)
@@ -214,7 +206,8 @@ export async function creditInboxOnce(args: {
214
206
  storage?: StorageLike
215
207
  force?: string[]
216
208
  classify?: (e: unknown) => CreditFailureKind
217
- accept: (payment: IncomingPayment) => Promise<void>
209
+ /** See `autoAcceptInbox`: `'duplicate'` leaves the box but is not counted as accepted. */
210
+ accept: (payment: IncomingPayment) => Promise<void | CreditOutcome>
218
211
  }): Promise<CreditInboxResult> {
219
212
  const force = args.force ?? []
220
213
  if (inFlight && force.length === 0) return inFlight