@fedimint/core 0.1.1 → 0.1.3

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.
Files changed (36) hide show
  1. package/dist/dts/FedimintWallet.d.ts +2 -1
  2. package/dist/dts/FedimintWallet.d.ts.map +1 -1
  3. package/dist/dts/WalletDirector.d.ts +16 -0
  4. package/dist/dts/WalletDirector.d.ts.map +1 -1
  5. package/dist/dts/services/BalanceService.d.ts +2 -1
  6. package/dist/dts/services/BalanceService.d.ts.map +1 -1
  7. package/dist/dts/services/FederationService.d.ts +2 -1
  8. package/dist/dts/services/FederationService.d.ts.map +1 -1
  9. package/dist/dts/services/LightningService.d.ts +2 -1
  10. package/dist/dts/services/LightningService.d.ts.map +1 -1
  11. package/dist/dts/services/MintService.d.ts +2 -1
  12. package/dist/dts/services/MintService.d.ts.map +1 -1
  13. package/dist/dts/services/RecoveryService.d.ts +2 -1
  14. package/dist/dts/services/RecoveryService.d.ts.map +1 -1
  15. package/dist/dts/services/WalletService.d.ts +2 -1
  16. package/dist/dts/services/WalletService.d.ts.map +1 -1
  17. package/dist/dts/transport/TransportClient.d.ts +3 -2
  18. package/dist/dts/transport/TransportClient.d.ts.map +1 -1
  19. package/dist/index.d.ts +18 -2
  20. package/dist/index.js +1 -1
  21. package/dist/index.js.map +1 -1
  22. package/dist/{testing.d-DpvbSA87.d.ts → testing.d-CJcyXM5Q.d.ts} +17 -9
  23. package/dist/testing.d.ts +1 -1
  24. package/dist/testing.js +1 -1
  25. package/dist/testing.js.map +1 -1
  26. package/package.json +6 -6
  27. package/src/FedimintWallet.ts +30 -22
  28. package/src/WalletDirector.ts +38 -3
  29. package/src/services/BalanceService.ts +11 -2
  30. package/src/services/FederationService.ts +21 -6
  31. package/src/services/LightningService.ts +20 -2
  32. package/src/services/MintService.ts +34 -10
  33. package/src/services/RecoveryService.ts +19 -3
  34. package/src/services/WalletService.ts +22 -7
  35. package/src/transport/TransportClient.ts +57 -17
  36. package/src/utils/logger.ts +2 -2
@@ -8,7 +8,9 @@ import {
8
8
  WalletService,
9
9
  } from './services'
10
10
 
11
- const DEFAULT_CLIENT_NAME = 'fm-default' as const
11
+ // The Rpc requires exactly 36 length uuid strings
12
+ // This is temporary until we have a proper client management system
13
+ const DEFAULT_CLIENT_NAME = 'dd5135b2-c228-41b7-a4f9-3b6e7afe3088' as const
12
14
 
13
15
  export class FedimintWallet {
14
16
  public balance: BalanceService
@@ -48,16 +50,19 @@ export class FedimintWallet {
48
50
  * lazyWallet.initialize();
49
51
  * lazyWallet.open();
50
52
  */
51
- constructor(private _client: TransportClient) {
53
+ constructor(
54
+ private _client: TransportClient,
55
+ private _clientName: string = DEFAULT_CLIENT_NAME,
56
+ ) {
52
57
  this._openPromise = new Promise((resolve) => {
53
58
  this._resolveOpen = resolve
54
59
  })
55
- this.mint = new MintService(this._client)
56
- this.lightning = new LightningService(this._client)
57
- this.balance = new BalanceService(this._client)
58
- this.federation = new FederationService(this._client)
59
- this.recovery = new RecoveryService(this._client)
60
- this.wallet = new WalletService(this._client)
60
+ this.mint = new MintService(this._client, this._clientName)
61
+ this.lightning = new LightningService(this._client, this._clientName)
62
+ this.balance = new BalanceService(this._client, this._clientName)
63
+ this.federation = new FederationService(this._client, this._clientName)
64
+ this.recovery = new RecoveryService(this._client, this._clientName)
65
+ this.wallet = new WalletService(this._client, this._clientName)
61
66
  }
62
67
 
63
68
  async waitForOpen() {
@@ -68,14 +73,17 @@ export class FedimintWallet {
68
73
  async open(clientName: string = DEFAULT_CLIENT_NAME) {
69
74
  // TODO: Determine if this should be safe or throw
70
75
  if (this._isOpen) throw new Error('The FedimintWallet is already open.')
71
- const { success } = await this._client.sendSingleMessage<{
72
- success: boolean
73
- }>('open', { clientName })
74
- if (success) {
75
- this._isOpen = !!success
76
+ try {
77
+ await this._client.sendSingleMessage('open_client', {
78
+ client_name: clientName,
79
+ })
80
+ this._isOpen = true
76
81
  this._resolveOpen()
82
+ return true
83
+ } catch (e) {
84
+ this._client.logger.error('Error opening client', e)
85
+ throw e
77
86
  }
78
- return success
79
87
  }
80
88
 
81
89
  async joinFederation(
@@ -88,15 +96,15 @@ export class FedimintWallet {
88
96
  'The FedimintWallet is already open. You can only call `joinFederation` on closed clients.',
89
97
  )
90
98
  try {
91
- const response = await this._client.sendSingleMessage<{
92
- success: boolean
93
- }>('join', { inviteCode, clientName })
94
- if (response.success) {
95
- this._isOpen = true
96
- this._resolveOpen()
97
- }
99
+ await this._client.sendSingleMessage('join_federation', {
100
+ invite_code: inviteCode,
101
+ client_name: clientName,
102
+ force_recover: false,
103
+ })
104
+ this._isOpen = true
105
+ this._resolveOpen()
98
106
 
99
- return response.success
107
+ return true
100
108
  } catch (e) {
101
109
  this._client.logger.error('Error joining federation', e)
102
110
  return false
@@ -45,7 +45,7 @@ export class WalletDirector {
45
45
  const response = this._client.sendSingleMessage<{
46
46
  config: FederationConfig
47
47
  federation_id: string
48
- }>('previewFederation', { inviteCode })
48
+ }>('preview_federation', { invite_code: inviteCode })
49
49
  return response
50
50
  }
51
51
 
@@ -83,7 +83,7 @@ export class WalletDirector {
83
83
  type: string
84
84
  data: JSONValue
85
85
  requestId: number
86
- }>('parseInviteCode', { inviteCode })
86
+ }>('parse_invite_code', { inviteCode })
87
87
  return response
88
88
  }
89
89
 
@@ -113,7 +113,42 @@ export class WalletDirector {
113
113
  type: string
114
114
  data: JSONValue
115
115
  requestId: number
116
- }>('parseBolt11Invoice', { invoiceStr })
116
+ }>('parse_bolt11_invoice', { invoiceStr })
117
117
  return response
118
118
  }
119
+
120
+ /**
121
+ * Generates and sets a new mnemonic phrase.
122
+ * @returns {Promise<string[]>} A promise that resolves to the generated mnemonic phrase.
123
+ */
124
+ async generateMnemonic(): Promise<string[]> {
125
+ const result = await this._client.sendSingleMessage<{ mnemonic: string[] }>(
126
+ 'generate_mnemonic',
127
+ )
128
+ return result.mnemonic
129
+ }
130
+
131
+ /**
132
+ * Retrieves the current mnemonic phrase.
133
+ * @returns {Promise<string[]>} A promise that resolves to the current mnemonic phrase.
134
+ */
135
+ async getMnemonic(): Promise<string[]> {
136
+ const result = await this._client.sendSingleMessage<{ mnemonic: string[] }>(
137
+ 'get_mnemonic',
138
+ )
139
+ return result.mnemonic
140
+ }
141
+
142
+ /**
143
+ * Sets the mnemonic phrase.
144
+ * @param {string[]} words - The mnemonic words to set.
145
+ * @returns {Promise<boolean>} A promise that resolves to true if the mnemonic was set successfully.
146
+ */
147
+ async setMnemonic(words: string[]): Promise<boolean> {
148
+ const result = await this._client.sendSingleMessage<{ success: boolean }>(
149
+ 'set_mnemonic',
150
+ { words },
151
+ )
152
+ return result.success
153
+ }
119
154
  }
@@ -6,11 +6,19 @@ import { TransportClient } from '../transport'
6
6
  * The Balance Service provides methods to interact with the balance of a Fedimint wallet.
7
7
  */
8
8
  export class BalanceService {
9
- constructor(private client: TransportClient) {}
9
+ constructor(
10
+ private client: TransportClient,
11
+ private clientName: string,
12
+ ) {}
10
13
 
11
14
  /** https://web.fedimint.org/core/FedimintWallet/BalanceService/getBalance */
12
15
  async getBalance() {
13
- return await this.client.rpcSingle<number>('', 'get_balance', {})
16
+ return await this.client.rpcSingle<number>(
17
+ '',
18
+ 'get_balance',
19
+ {},
20
+ this.clientName,
21
+ )
14
22
  }
15
23
 
16
24
  /** https://web.fedimint.org/core/FedimintWallet/BalanceService/subscribeBalance */
@@ -22,6 +30,7 @@ export class BalanceService {
22
30
  '',
23
31
  'subscribe_balance_changes',
24
32
  {},
33
+ this.clientName,
25
34
  (res) => onSuccess(parseInt(res)),
26
35
  onError,
27
36
  )
@@ -12,20 +12,33 @@ import type {
12
12
  import { TransportClient } from '../transport'
13
13
 
14
14
  export class FederationService {
15
- constructor(private client: TransportClient) {}
15
+ constructor(
16
+ private client: TransportClient,
17
+ private clientName: string,
18
+ ) {}
16
19
 
17
20
  async getConfig() {
18
- return await this.client.rpcSingle('', 'get_config', {})
21
+ return await this.client.rpcSingle('', 'get_config', {}, this.clientName)
19
22
  }
20
23
 
21
24
  async getFederationId() {
22
- return await this.client.rpcSingle<string>('', 'get_federation_id', {})
25
+ return await this.client.rpcSingle<string>(
26
+ '',
27
+ 'get_federation_id',
28
+ {},
29
+ this.clientName,
30
+ )
23
31
  }
24
32
 
25
33
  async getInviteCode(peer: number = 0) {
26
- return await this.client.rpcSingle<string | null>('', 'get_invite_code', {
27
- peer,
28
- })
34
+ return await this.client.rpcSingle<string | null>(
35
+ '',
36
+ 'get_invite_code',
37
+ {
38
+ peer,
39
+ },
40
+ this.clientName,
41
+ )
29
42
  }
30
43
 
31
44
  async listOperations(
@@ -39,6 +52,7 @@ export class FederationService {
39
52
  limit: limit ?? null,
40
53
  last_seen: last_seen ?? null,
41
54
  },
55
+ this.clientName,
42
56
  )
43
57
  }
44
58
 
@@ -47,6 +61,7 @@ export class FederationService {
47
61
  '',
48
62
  'get_operation',
49
63
  { operation_id: operationId },
64
+ this.clientName,
50
65
  )
51
66
  }
52
67
 
@@ -11,7 +11,10 @@ import type {
11
11
  } from '../types'
12
12
 
13
13
  export class LightningService {
14
- constructor(private client: TransportClient) {}
14
+ constructor(
15
+ private client: TransportClient,
16
+ private clientName: string,
17
+ ) {}
15
18
 
16
19
  /** https://web.fedimint.org/core/FedimintWallet/LightningService/createInvoice#lightning-createinvoice */
17
20
  async createInvoice(
@@ -32,6 +35,7 @@ export class LightningService {
32
35
  extra_meta: extraMeta ?? {},
33
36
  gateway,
34
37
  },
38
+ this.clientName,
35
39
  )
36
40
  }
37
41
 
@@ -57,6 +61,7 @@ export class LightningService {
57
61
  extra_meta: extraMeta ?? {},
58
62
  gateway,
59
63
  },
64
+ this.clientName,
60
65
  )
61
66
  }
62
67
 
@@ -74,6 +79,7 @@ export class LightningService {
74
79
  indices,
75
80
  extra_meta: extraMeta ?? {},
76
81
  },
82
+ this.clientName,
77
83
  )
78
84
  }
79
85
 
@@ -98,6 +104,7 @@ export class LightningService {
98
104
  invoice,
99
105
  extra_meta: extraMeta ?? {},
100
106
  },
107
+ this.clientName,
101
108
  )
102
109
  }
103
110
 
@@ -151,6 +158,7 @@ export class LightningService {
151
158
  'ln',
152
159
  'subscribe_internal_pay',
153
160
  { operation_id: operation_id },
161
+ this.clientName,
154
162
  onSuccess,
155
163
  onError,
156
164
  )
@@ -166,6 +174,7 @@ export class LightningService {
166
174
  'ln',
167
175
  'subscribe_ln_claim',
168
176
  { operation_id: operationId },
177
+ this.clientName,
169
178
  onSuccess,
170
179
  onError,
171
180
  )
@@ -183,6 +192,7 @@ export class LightningService {
183
192
  'ln',
184
193
  'subscribe_ln_pay',
185
194
  { operation_id: operationId },
195
+ this.clientName,
186
196
  onSuccess,
187
197
  onError,
188
198
  )
@@ -230,6 +240,7 @@ export class LightningService {
230
240
  'ln',
231
241
  'subscribe_ln_receive',
232
242
  { operation_id: operationId },
243
+ this.clientName,
233
244
  onSuccess,
234
245
  onError,
235
246
  )
@@ -272,6 +283,7 @@ export class LightningService {
272
283
  gateway_id: gatewayId,
273
284
  force_internal: forceInternal,
274
285
  },
286
+ this.clientName,
275
287
  )
276
288
  }
277
289
 
@@ -280,10 +292,16 @@ export class LightningService {
280
292
  'ln',
281
293
  'list_gateways',
282
294
  {},
295
+ this.clientName,
283
296
  )
284
297
  }
285
298
 
286
299
  async updateGatewayCache() {
287
- return await this.client.rpcSingle('ln', 'update_gateway_cache', {})
300
+ return await this.client.rpcSingle(
301
+ 'ln',
302
+ 'update_gateway_cache',
303
+ {},
304
+ this.clientName,
305
+ )
288
306
  }
289
307
  }
@@ -11,7 +11,10 @@ import type {
11
11
  } from '../types'
12
12
 
13
13
  export class MintService {
14
- constructor(private client: TransportClient) {}
14
+ constructor(
15
+ private client: TransportClient,
16
+ private clientName: string,
17
+ ) {}
15
18
 
16
19
  /** https://web.fedimint.org/core/FedimintWallet/MintService/redeemEcash */
17
20
  async redeemEcash(notes: string) {
@@ -22,6 +25,7 @@ export class MintService {
22
25
  oob_notes: notes, // "out of band notes"
23
26
  extra_meta: null,
24
27
  },
28
+ this.clientName,
25
29
  )
26
30
  }
27
31
 
@@ -33,6 +37,7 @@ export class MintService {
33
37
  oob_notes: oobNotes,
34
38
  extra_meta: extraMeta,
35
39
  },
40
+ this.clientName,
36
41
  )
37
42
  }
38
43
 
@@ -45,6 +50,7 @@ export class MintService {
45
50
  'mint',
46
51
  'subscribe_reissue_external_notes',
47
52
  { operation_id: operationId },
53
+ this.clientName,
48
54
  onSuccess,
49
55
  onError,
50
56
  )
@@ -76,6 +82,7 @@ export class MintService {
76
82
  include_invite: includeInvite,
77
83
  extra_meta: extraMeta,
78
84
  },
85
+ this.clientName,
79
86
  )
80
87
  const notes = res[1]
81
88
  const operationId = res[0]
@@ -88,15 +95,25 @@ export class MintService {
88
95
 
89
96
  /** https://web.fedimint.org/core/FedimintWallet/MintService/parseEcash */
90
97
  async parseNotes(oobNotes: string) {
91
- return await this.client.rpcSingle<MSats>('mint', 'validate_notes', {
92
- oob_notes: oobNotes,
93
- })
98
+ return await this.client.rpcSingle<MSats>(
99
+ 'mint',
100
+ 'validate_notes',
101
+ {
102
+ oob_notes: oobNotes,
103
+ },
104
+ this.clientName,
105
+ )
94
106
  }
95
107
 
96
108
  async tryCancelSpendNotes(operationId: string) {
97
- await this.client.rpcSingle('mint', 'try_cancel_spend_notes', {
98
- operation_id: operationId,
99
- })
109
+ await this.client.rpcSingle(
110
+ 'mint',
111
+ 'try_cancel_spend_notes',
112
+ {
113
+ operation_id: operationId,
114
+ },
115
+ this.clientName,
116
+ )
100
117
  }
101
118
 
102
119
  subscribeSpendNotes(
@@ -108,15 +125,21 @@ export class MintService {
108
125
  'mint',
109
126
  'subscribe_spend_notes',
110
127
  { operation_id: operationId },
128
+ this.clientName,
111
129
  (res) => onSuccess(res),
112
130
  onError,
113
131
  )
114
132
  }
115
133
 
116
134
  async awaitSpendOobRefund(operationId: string) {
117
- return await this.client.rpcSingle('mint', 'await_spend_oob_refund', {
118
- operation_id: operationId,
119
- })
135
+ return await this.client.rpcSingle(
136
+ 'mint',
137
+ 'await_spend_oob_refund',
138
+ {
139
+ operation_id: operationId,
140
+ },
141
+ this.clientName,
142
+ )
120
143
  }
121
144
 
122
145
  async getNotesByDenomination() {
@@ -124,6 +147,7 @@ export class MintService {
124
147
  'mint',
125
148
  'note_counts_by_denomination',
126
149
  {},
150
+ this.clientName,
127
151
  )
128
152
  }
129
153
  }
@@ -2,18 +2,27 @@ import type { JSONValue } from '../types'
2
2
  import { TransportClient } from '../transport'
3
3
 
4
4
  export class RecoveryService {
5
- constructor(private client: TransportClient) {}
5
+ constructor(
6
+ private client: TransportClient,
7
+ private clientName: string,
8
+ ) {}
6
9
 
7
10
  async hasPendingRecoveries() {
8
11
  return await this.client.rpcSingle<boolean>(
9
12
  '',
10
13
  'has_pending_recoveries',
11
14
  {},
15
+ this.clientName,
12
16
  )
13
17
  }
14
18
 
15
19
  async waitForAllRecoveries() {
16
- await this.client.rpcSingle('', 'wait_for_all_recoveries', {})
20
+ await this.client.rpcSingle(
21
+ '',
22
+ 'wait_for_all_recoveries',
23
+ {},
24
+ this.clientName,
25
+ )
17
26
  }
18
27
 
19
28
  subscribeToRecoveryProgress(
@@ -23,6 +32,13 @@ export class RecoveryService {
23
32
  return this.client.rpcStream<{
24
33
  module_id: number
25
34
  progress: JSONValue
26
- }>('', 'subscribe_to_recovery_progress', {}, onSuccess, onError)
35
+ }>(
36
+ '',
37
+ 'subscribe_to_recovery_progress',
38
+ {},
39
+ this.clientName,
40
+ onSuccess,
41
+ onError,
42
+ )
27
43
  }
28
44
  }
@@ -7,10 +7,18 @@ import {
7
7
  import { TransportClient } from '../transport'
8
8
 
9
9
  export class WalletService {
10
- constructor(private client: TransportClient) {}
10
+ constructor(
11
+ private client: TransportClient,
12
+ private clientName: string,
13
+ ) {}
11
14
 
12
15
  async getWalletSummary(): Promise<WalletSummary> {
13
- return await this.client.rpcSingle('wallet', 'get_wallet_summary', {})
16
+ return await this.client.rpcSingle(
17
+ 'wallet',
18
+ 'get_wallet_summary',
19
+ {},
20
+ this.clientName,
21
+ )
14
22
  }
15
23
 
16
24
  async generateAddress(extraMeta: JSONValue = {}) {
@@ -20,6 +28,7 @@ export class WalletService {
20
28
  {
21
29
  extra_meta: extraMeta,
22
30
  },
31
+ this.clientName,
23
32
  )
24
33
  }
25
34
 
@@ -28,11 +37,16 @@ export class WalletService {
28
37
  address: string,
29
38
  extraMeta: JSONValue = {},
30
39
  ): Promise<{ operation_id: string }> {
31
- return await this.client.rpcSingle('wallet', 'peg_out', {
32
- amount_sat: amountSat,
33
- destination_address: address,
34
- extra_meta: extraMeta,
35
- })
40
+ return await this.client.rpcSingle(
41
+ 'wallet',
42
+ 'peg_out',
43
+ {
44
+ amount_sat: amountSat,
45
+ destination_address: address,
46
+ extra_meta: extraMeta,
47
+ },
48
+ this.clientName,
49
+ )
36
50
  }
37
51
  subscribeDeposit(
38
52
  operation_id: string,
@@ -43,6 +57,7 @@ export class WalletService {
43
57
  'ln',
44
58
  'subscribe_deposit',
45
59
  { operation_id: operation_id },
60
+ this.clientName,
46
61
  onSuccess,
47
62
  onError,
48
63
  )
@@ -38,36 +38,58 @@ export class TransportClient {
38
38
  }
39
39
 
40
40
  // Idempotent setup - Loads the wasm module
41
- initialize() {
41
+ initialize(): Promise<boolean>
42
+ initialize(testFilename: string): Promise<boolean>
43
+ initialize(testFilename?: string): Promise<boolean> {
42
44
  if (this.initPromise) return this.initPromise
43
- this.initPromise = this.sendSingleMessage('init')
45
+ if (testFilename) {
46
+ this.initPromise = this.sendSingleMessage('init', {
47
+ filename: testFilename,
48
+ })
49
+ } else {
50
+ this.initPromise = this.sendSingleMessage('init')
51
+ }
44
52
  return this.initPromise
45
53
  }
46
54
 
47
55
  private handleLogMessage(message: TransportMessage) {
48
- const { type, level, message: logMessage, ...data } = message
49
- this.logger.info(String(level), String(logMessage), data)
56
+ const { type, level = 'debug', message: logMessage, ...data } = message
57
+ this.logger.log(String(level), `Transport Log: ${String(logMessage)}`, data)
50
58
  }
51
59
 
52
60
  private handleTransportError = (error: unknown) => {
53
- this.logger.error('TransportClient error', error)
61
+ this.logger.warn(
62
+ 'TransportClient error',
63
+ JSON.stringify(error, [
64
+ 'message',
65
+ 'arguments',
66
+ 'type',
67
+ 'name',
68
+ 'request_id',
69
+ ]),
70
+ )
54
71
  }
55
72
 
56
73
  private handleTransportMessage = (message: TransportMessage) => {
57
- const { type, requestId, ...data } = message
74
+ const { type, request_id, ...data } = message
58
75
  if (type === 'log') {
59
76
  this.handleLogMessage(message)
60
77
  }
78
+
61
79
  const streamCallback =
62
- requestId !== undefined ? this.requestCallbacks.get(requestId) : undefined
80
+ request_id !== undefined
81
+ ? this.requestCallbacks.get(request_id)
82
+ : undefined
63
83
  // TODO: Handle errors... maybe have another callbacks list for errors?
64
- this.logger.debug('TransportClient - handleTransportMessage', message)
65
84
  if (streamCallback) {
85
+ this.logger.debug(
86
+ 'TransportClient - handleTransportMessage - callback',
87
+ message,
88
+ )
66
89
  streamCallback(data) // {data: something} OR {error: something}
67
- } else if (requestId !== undefined) {
90
+ } else if (request_id !== undefined && type !== 'end') {
68
91
  this.logger.warn(
69
92
  'TransportClient - handleTransportMessage - received message with no callback',
70
- requestId,
71
93
  message,
72
94
  )
73
95
  }
@@ -98,7 +120,7 @@ export class TransportClient {
98
120
  requestId,
99
121
  response,
100
122
  )
101
- if (response.data) resolve(response.data)
123
+ if (response.data !== undefined) resolve(response.data)
102
124
  else if (response.error) reject(response.error)
103
125
  else
104
126
  this.logger.warn(
@@ -143,6 +165,7 @@ export class TransportClient {
143
165
  module: ModuleKind,
144
166
  method: string,
145
167
  body: Body,
168
+ clientName: string,
146
169
  onSuccess: (res: Response) => void,
147
170
  onError: (res: StreamError['error']) => void,
148
171
  onEnd: () => void = () => {},
@@ -154,6 +177,7 @@ export class TransportClient {
154
177
  module,
155
178
  method,
156
179
  body,
180
+ clientName,
157
181
  )
158
182
  let unsubscribe: (value: void) => void = () => {}
159
183
  let isSubscribed = false
@@ -177,6 +201,7 @@ export class TransportClient {
177
201
  module,
178
202
  method,
179
203
  body,
204
+ clientName,
180
205
  onSuccess,
181
206
  onError,
182
207
  onEnd,
@@ -196,6 +221,7 @@ export class TransportClient {
196
221
  module: ModuleKind,
197
222
  method: string,
198
223
  body: Body,
224
+ clientName: string,
199
225
  onSuccess: (res: Response) => void,
200
226
  onError: (res: StreamError['error']) => void,
201
227
  onEnd: () => void = () => {},
@@ -213,14 +239,15 @@ export class TransportClient {
213
239
  }
214
240
  })
215
241
  this.transport.postMessage({
216
- type: 'rpc',
217
- payload: { module, method, body },
242
+ type: 'client_rpc',
243
+ payload: { client_name: clientName, module, method, payload: body },
218
244
  requestId,
219
245
  })
220
246
 
221
247
  unsubscribePromise.then(() => {
222
248
  this.transport.postMessage({
223
- type: 'unsubscribe',
249
+ type: 'cancel_rpc',
250
+ payload: { cancel_request_id: requestId },
224
251
  requestId,
225
252
  })
226
253
  this.requestCallbacks.delete(requestId)
@@ -230,15 +257,28 @@ export class TransportClient {
230
257
  rpcSingle<
231
258
  Response extends JSONValue = JSONValue,
232
259
  Error extends string = string,
233
- >(module: ModuleKind, method: string, body: JSONValue) {
260
+ >(
261
+ module: ModuleKind,
262
+ method: string,
263
+ body: JSONValue,
264
+ clientName: string,
265
+ ): Promise<Response> {
234
266
  this.logger.debug('TransportClient - rpcSingle', module, method, body)
235
267
  return new Promise<Response>((resolve, reject) => {
236
- this.rpcStream<Response>(module, method, body, resolve, reject)
268
+ this.rpcStream<Response>(
269
+ module,
270
+ method,
271
+ body,
272
+ clientName,
273
+ resolve,
274
+ reject,
275
+ )
237
276
  })
238
277
  }
239
278
 
240
279
  async cleanup() {
241
- await this.sendSingleMessage('cleanup')
280
+ const res = await this.sendSingleMessage('cleanup')
281
+ this.logger.info('TransportClient - cleanup', res)
242
282
  this.requestCounter = 0
243
283
  this.initPromise = undefined
244
284
  this.requestCallbacks.clear()