@credo-ts/didcomm-transport-ble 0.0.0-stage → 0.4.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 +201 -0
- package/README.md +134 -2
- package/build/index.d.mts +41 -0
- package/build/index.mjs +85 -0
- package/build/index.mjs.map +1 -0
- package/package.json +43 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,135 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<br />
|
|
3
|
+
<img
|
|
4
|
+
alt="Credo logo"
|
|
5
|
+
src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png"
|
|
6
|
+
height="250px"
|
|
7
|
+
/>
|
|
8
|
+
</p>
|
|
9
|
+
<h1 align="center"><b>Bluetooth Low Energy transport for Credo</b></h1>
|
|
10
|
+
<p align="center">
|
|
11
|
+
<a
|
|
12
|
+
href="https://raw.githubusercontent.com/openwallet-foundation/credo-ts-didcomm-ext/main/LICENSE"
|
|
13
|
+
><img
|
|
14
|
+
alt="License"
|
|
15
|
+
src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"
|
|
16
|
+
/></a>
|
|
17
|
+
<a href="https://www.typescriptlang.org/"
|
|
18
|
+
><img
|
|
19
|
+
alt="typescript"
|
|
20
|
+
src="https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg"
|
|
21
|
+
/></a>
|
|
22
|
+
<a href="https://www.npmjs.com/package/@credo-ts/didcomm-transport-ble"
|
|
23
|
+
><img
|
|
24
|
+
alt="@credo-ts/didcomm-transport-ble version"
|
|
25
|
+
src="https://img.shields.io/npm/v/@credo-ts/didcomm-transport-ble"
|
|
26
|
+
/></a>
|
|
27
|
+
<br />
|
|
28
|
+
</p>
|
|
2
29
|
|
|
3
|
-
|
|
30
|
+
The Credo BLE Transport package provides a simple way to add Bluetooth Low Energy (BLE) data transport into Credo React Native mobile agents.
|
|
31
|
+
|
|
32
|
+
> **Warning:** This transport has not yet been tested with Credo 0.7.x. It may be unstable or not work as expected.
|
|
33
|
+
|
|
34
|
+
It implements the same transport interfaces as [@credo-ts/didcomm](https://www.npmjs.com/package/@credo-ts/didcomm).
|
|
35
|
+
|
|
36
|
+
With this transport enabled, Credo React Native mobile agents gain the ability to do offline DIDComm exchanges using Bluetooth Low Energy (BLE).
|
|
37
|
+
|
|
38
|
+
To keep this transport implementation focused on the 'DIDComm' wrapper needed to make it useful to Credo agents, this transport package is built on this [BLE DIDComm SDK](https://www.npmjs.com/package/@animo-id/react-native-ble-didcomm).
|
|
39
|
+
|
|
40
|
+
The **BLE DIDComm SDK** implements the core Bluetooth hardware interface for Android (in Kotlin) and iOS (Swift), and exposes the simple APIs that this BLE transport implementation uses.
|
|
41
|
+
|
|
42
|
+
And to keep the implementation simple, this transport only implements the core message listening and receiving functionality, and leaves the powerful startup and service controls provided by the BLE DIDComm SDK, to user control and discretion.
|
|
43
|
+
|
|
44
|
+
We're this discussing if this is the best approach to use in future versions. If after using this first version and you have strong opinions on this, kindly join the conversation [here](https://github.com/openwallet-foundation/credo-ts-ext/issues/197).
|
|
45
|
+
|
|
46
|
+
## Installing the required dependencies
|
|
47
|
+
|
|
48
|
+
This package requires Credo 0.7.x and React Native 0.73.4 or newer.
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
npm install @credo-ts/didcomm-transport-ble @credo-ts/core @credo-ts/didcomm @credo-ts/react-native @animo-id/react-native-ble-didcomm
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Configuration
|
|
55
|
+
|
|
56
|
+
Configuring your agent to use the transport is simple; all you need is to import the transports, `DidCommBleOutboundTransport` and `DidCommBleInboundTransport`, from the package, and register them on the agent, either before or after agent initialization.
|
|
57
|
+
|
|
58
|
+
The only difference is that unlike HTTP and WebSockets, an agent can only register one of either outbound, `DidCommBleOutboundTransport`, or inbound, `DidCommBleInboundTransport`, transport, depending on which role the agent wants to take in the BLE DIDComm exchange.
|
|
59
|
+
|
|
60
|
+
The BLE DIDComm SDK provides two controllers: `Central`, to be used by the agent who will be initiating the exchange (creating and sending the out-of-band invitation), and `Peripheral`, for the agent who will be receiving and accepting the invitation.
|
|
61
|
+
|
|
62
|
+
This means that the agent acting as the connection initiator should use the `Central` controller with `DidCommBleInboundTransport`, while the agent acting as the connection receptor uses the Peripheral controller with `DidCommBleOutboundTransport`.
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
// If you want to register the transports only after initializing the agent, you can do this anywhere else in your app, and just leave out the agent config and initialization
|
|
66
|
+
|
|
67
|
+
import { DidCommBleOutboundTransport, DidCommBleInboundTransport } from '@credo-ts/didcomm-transport-ble'
|
|
68
|
+
import { Agent } from '@credo-ts/core'
|
|
69
|
+
import { DidCommModule } from '@credo-ts/didcomm'
|
|
70
|
+
import { agentDependencies } from '@credo-ts/react-native'
|
|
71
|
+
import {
|
|
72
|
+
Central,
|
|
73
|
+
Peripheral,
|
|
74
|
+
DEFAULT_DIDCOMM_SERVICE_CHARACTERISTIC_UUID,
|
|
75
|
+
DEFAULT_DIDCOMM_MESSAGE_CHARACTERISTIC_UUID,
|
|
76
|
+
DEFAULT_DIDCOMM_INDICATE_CHARACTERISTIC_UUID,
|
|
77
|
+
} from '@animo-id/react-native-ble-didcomm'
|
|
78
|
+
|
|
79
|
+
const createAgent = async () => {
|
|
80
|
+
const agent = new Agent({
|
|
81
|
+
config: {
|
|
82
|
+
// ... Credo Config ... //
|
|
83
|
+
},
|
|
84
|
+
modules: {
|
|
85
|
+
didcomm: new DidCommModule(),
|
|
86
|
+
// ... Credo Module config
|
|
87
|
+
},
|
|
88
|
+
dependencies: agentDependencies,
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
// Instantiate the BLE controller you want
|
|
92
|
+
const central = new Central() // const peripheral = new Peripheral() for the peripheral agent
|
|
93
|
+
|
|
94
|
+
// It is important that you start the BLE controllers before you use/register them on your agent
|
|
95
|
+
await central.start() // await peripheral.start()
|
|
96
|
+
|
|
97
|
+
/* IMPORTANT: Setting up the service, messaging and indication UUIDs.
|
|
98
|
+
The values passed must be the same in the central and peripheral,
|
|
99
|
+
as this is how both devices will be able to recognize each other.
|
|
100
|
+
There are default values for these that can be imported,
|
|
101
|
+
but if you want to maintain control over the sessions and/or prevent collisions
|
|
102
|
+
(due to multiple other devices broadcasting using these same values),
|
|
103
|
+
you might want to generate your own serviceUUID and share it across both mobile agents
|
|
104
|
+
(using a scannable QR code or something similar that allows easy sharing with little overhead)
|
|
105
|
+
|
|
106
|
+
This can be done anywhere after starting the controller (step above),
|
|
107
|
+
even after registering the controller as a transport on the agent (step below) */
|
|
108
|
+
|
|
109
|
+
const uuid = '56847593-40ea-4a92-bd8c-e1514dca1c61'
|
|
110
|
+
await central.setService({
|
|
111
|
+
serviceUUID: uuid || DEFAULT_DIDCOMM_SERVICE_CHARACTERISTIC_UUID,
|
|
112
|
+
messagingUUID: DEFAULT_DIDCOMM_MESSAGE_CHARACTERISTIC_UUID,
|
|
113
|
+
indicationUUID: DEFAULT_DIDCOMM_INDICATE_CHARACTERISTIC_UUID,
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
/* On the peripheral agent
|
|
117
|
+
await peripheral.setService({
|
|
118
|
+
serviceUUID: uuid || DEFAULT_DIDCOMM_SERVICE_CHARACTERISTIC_UUID,
|
|
119
|
+
messagingUUID: DEFAULT_DIDCOMM_MESSAGE_CHARACTERISTIC_UUID,
|
|
120
|
+
indicationUUID: DEFAULT_DIDCOMM_INDICATE_CHARACTERISTIC_UUID
|
|
121
|
+
})
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
// Register the transport on the agent's DIDComm module
|
|
125
|
+
const bleInboundTransport = new DidCommBleInboundTransport(central) // const bleOutboundTransport = new DidCommBleOutboundTransport(peripheral)
|
|
126
|
+
agent.didcomm.registerInboundTransport(bleInboundTransport) // agent.didcomm.registerOutboundTransport(bleOutboundTransport)
|
|
127
|
+
|
|
128
|
+
await agent.initialize()
|
|
129
|
+
|
|
130
|
+
return agent
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Inside your React Native app/component
|
|
134
|
+
const agent = await createAgent()
|
|
135
|
+
```
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { AgentContext } from "@credo-ts/core";
|
|
2
|
+
import { DidCommEncryptedMessage, DidCommInboundTransport, DidCommOutboundPackage, DidCommOutboundTransport, DidCommTransportSession } from "@credo-ts/didcomm";
|
|
3
|
+
import { Ble } from "@animo-id/react-native-ble-didcomm";
|
|
4
|
+
|
|
5
|
+
//#region src/transports/BleInboundTransport.d.ts
|
|
6
|
+
declare class DidCommBleInboundTransport implements DidCommInboundTransport {
|
|
7
|
+
supportedSchemes: string[];
|
|
8
|
+
private messenger;
|
|
9
|
+
private messageListener?;
|
|
10
|
+
private session;
|
|
11
|
+
private disconnectionListener?;
|
|
12
|
+
private logger?;
|
|
13
|
+
constructor(messenger: Ble);
|
|
14
|
+
start(agentContext: AgentContext): Promise<void>;
|
|
15
|
+
stop(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/transports/BleOutboundTransport.d.ts
|
|
19
|
+
declare class DidCommBleOutboundTransport implements DidCommOutboundTransport {
|
|
20
|
+
supportedSchemes: string[];
|
|
21
|
+
private messenger;
|
|
22
|
+
private logger?;
|
|
23
|
+
constructor(messenger: Ble);
|
|
24
|
+
start(agentContext: AgentContext): Promise<void>;
|
|
25
|
+
sendMessage(outboundPackage: DidCommOutboundPackage): Promise<void>;
|
|
26
|
+
stop(): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/transports/BleTransportSession.d.ts
|
|
30
|
+
declare class DidCommBleTransportSession implements DidCommTransportSession {
|
|
31
|
+
readonly type = "ble";
|
|
32
|
+
id: string;
|
|
33
|
+
private agentContext;
|
|
34
|
+
private messenger;
|
|
35
|
+
constructor(id: string, messenger: Ble, agentContext: AgentContext);
|
|
36
|
+
send(agentContext: AgentContext, encryptedMessage: DidCommEncryptedMessage): Promise<void>;
|
|
37
|
+
close(): Promise<void>;
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { DidCommBleInboundTransport, DidCommBleOutboundTransport, DidCommBleTransportSession };
|
|
41
|
+
//# sourceMappingURL=index.d.mts.map
|
package/build/index.mjs
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { CredoError, utils } from "@credo-ts/core";
|
|
2
|
+
import { DidCommMessageReceiver, DidCommTransportService } from "@credo-ts/didcomm";
|
|
3
|
+
|
|
4
|
+
//#region src/transports/BleTransportSession.ts
|
|
5
|
+
var DidCommBleTransportSession = class {
|
|
6
|
+
constructor(id, messenger, agentContext) {
|
|
7
|
+
this.type = "ble";
|
|
8
|
+
this.id = id ?? utils.uuid();
|
|
9
|
+
this.messenger = messenger;
|
|
10
|
+
this.agentContext = agentContext;
|
|
11
|
+
}
|
|
12
|
+
async send(agentContext, encryptedMessage) {
|
|
13
|
+
const serializedMessage = JSON.stringify(encryptedMessage);
|
|
14
|
+
agentContext.config.logger.debug("Sending BLE inbound message via session");
|
|
15
|
+
await this.messenger.sendMessage(serializedMessage);
|
|
16
|
+
}
|
|
17
|
+
async close() {
|
|
18
|
+
this.agentContext.config.logger.debug("Stopping BLE inbound session");
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/transports/BleInboundTransport.ts
|
|
24
|
+
var DidCommBleInboundTransport = class {
|
|
25
|
+
constructor(messenger) {
|
|
26
|
+
this.supportedSchemes = ["ble"];
|
|
27
|
+
this.messenger = messenger;
|
|
28
|
+
}
|
|
29
|
+
async start(agentContext) {
|
|
30
|
+
this.logger = agentContext.config.logger;
|
|
31
|
+
this.logger.debug("Starting BLE inbound transport");
|
|
32
|
+
this.session = new DidCommBleTransportSession(utils.uuid(), this.messenger, agentContext);
|
|
33
|
+
const messageListener = async (data) => {
|
|
34
|
+
const message = data.message;
|
|
35
|
+
const messageReceiver = agentContext.dependencyManager.resolve(DidCommMessageReceiver);
|
|
36
|
+
try {
|
|
37
|
+
const encryptedMessage = await JSON.parse(message);
|
|
38
|
+
await messageReceiver.receiveMessage(encryptedMessage, { session: this.session });
|
|
39
|
+
} catch (error) {
|
|
40
|
+
this.logger?.error(`Error processing message: ${error}`);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
this.messageListener = this.messenger.registerMessageListener(messageListener);
|
|
44
|
+
const disconnectionListener = async (data) => {
|
|
45
|
+
this.logger?.debug("BLE disconnection detected", { data });
|
|
46
|
+
agentContext.dependencyManager.resolve(DidCommTransportService).removeSession(this.session);
|
|
47
|
+
};
|
|
48
|
+
this.disconnectionListener = this.messenger.registerOnDisconnectedListener(disconnectionListener);
|
|
49
|
+
}
|
|
50
|
+
async stop() {
|
|
51
|
+
this.logger?.debug("Stopping BLE inbound transport");
|
|
52
|
+
this.messageListener?.remove();
|
|
53
|
+
this.disconnectionListener?.remove();
|
|
54
|
+
await this.messenger.shutdown();
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/transports/BleOutboundTransport.ts
|
|
60
|
+
var DidCommBleOutboundTransport = class {
|
|
61
|
+
constructor(messenger) {
|
|
62
|
+
this.supportedSchemes = ["ble"];
|
|
63
|
+
this.messenger = messenger;
|
|
64
|
+
}
|
|
65
|
+
async start(agentContext) {
|
|
66
|
+
this.logger = agentContext.config.logger;
|
|
67
|
+
this.logger.debug("Starting BLE outbound transport");
|
|
68
|
+
}
|
|
69
|
+
async sendMessage(outboundPackage) {
|
|
70
|
+
const { payload, endpoint } = outboundPackage;
|
|
71
|
+
if (!endpoint) throw new CredoError(`Missing endpoint. I don't know how and where to send the message.`);
|
|
72
|
+
this.logger?.debug(`Sending outbound message to endpoint '${endpoint}'`, { payload });
|
|
73
|
+
const serializedMessage = JSON.stringify(payload);
|
|
74
|
+
this.logger?.debug("Sending BLE outbound message");
|
|
75
|
+
await this.messenger.sendMessage(serializedMessage);
|
|
76
|
+
}
|
|
77
|
+
async stop() {
|
|
78
|
+
this.logger?.debug("Stopping BLE outbound transport");
|
|
79
|
+
await this.messenger.shutdown();
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
84
|
+
export { DidCommBleInboundTransport, DidCommBleOutboundTransport, DidCommBleTransportSession };
|
|
85
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/transports/BleTransportSession.ts","../src/transports/BleInboundTransport.ts","../src/transports/BleOutboundTransport.ts"],"sourcesContent":["import type { Ble } from '@animo-id/react-native-ble-didcomm'\nimport type { AgentContext } from '@credo-ts/core'\nimport { utils } from '@credo-ts/core'\nimport type { DidCommEncryptedMessage, DidCommTransportSession } from '@credo-ts/didcomm'\n\nexport class DidCommBleTransportSession implements DidCommTransportSession {\n public readonly type = 'ble'\n public id: string\n\n private agentContext: AgentContext\n private messenger: Ble\n\n public constructor(id: string, messenger: Ble, agentContext: AgentContext) {\n this.id = id ?? utils.uuid()\n this.messenger = messenger\n this.agentContext = agentContext\n }\n\n public async send(agentContext: AgentContext, encryptedMessage: DidCommEncryptedMessage): Promise<void> {\n const serializedMessage = JSON.stringify(encryptedMessage)\n\n agentContext.config.logger.debug('Sending BLE inbound message via session')\n await this.messenger.sendMessage(serializedMessage)\n }\n\n public async close(): Promise<void> {\n this.agentContext.config.logger.debug('Stopping BLE inbound session')\n }\n}\n","import type { Ble } from '@animo-id/react-native-ble-didcomm'\nimport type { AgentContext, Logger } from '@credo-ts/core'\nimport { utils } from '@credo-ts/core'\nimport type { DidCommInboundTransport } from '@credo-ts/didcomm'\nimport { DidCommMessageReceiver, DidCommTransportService } from '@credo-ts/didcomm'\n\nimport { DidCommBleTransportSession } from './BleTransportSession'\n\ntype EmitterSubscription = {\n remove: () => void\n}\n\nexport class DidCommBleInboundTransport implements DidCommInboundTransport {\n public supportedSchemes: string[] = ['ble']\n private messenger: Ble\n private messageListener?: EmitterSubscription\n private session!: DidCommBleTransportSession\n private disconnectionListener?: EmitterSubscription\n private logger?: Logger\n\n public constructor(messenger: Ble) {\n this.messenger = messenger\n }\n\n public async start(agentContext: AgentContext): Promise<void> {\n this.logger = agentContext.config.logger\n this.logger.debug('Starting BLE inbound transport')\n\n const sessionId = utils.uuid()\n this.session = new DidCommBleTransportSession(sessionId, this.messenger, agentContext)\n\n const messageListener = async (data: { message: string }) => {\n const message = data.message\n\n const messageReceiver = agentContext.dependencyManager.resolve(DidCommMessageReceiver)\n\n try {\n const encryptedMessage = await JSON.parse(message)\n\n await messageReceiver.receiveMessage(encryptedMessage, {\n session: this.session,\n })\n } catch (error) {\n this.logger?.error(`Error processing message: ${error}`)\n }\n }\n\n this.messageListener = this.messenger.registerMessageListener(messageListener)\n\n const disconnectionListener = async (data: { identifier: string }) => {\n this.logger?.debug('BLE disconnection detected', { data })\n\n const transportService = agentContext.dependencyManager.resolve(DidCommTransportService)\n transportService.removeSession(this.session)\n }\n\n this.disconnectionListener = this.messenger.registerOnDisconnectedListener(disconnectionListener)\n }\n\n public async stop(): Promise<void> {\n this.logger?.debug('Stopping BLE inbound transport')\n\n this.messageListener?.remove()\n this.disconnectionListener?.remove()\n await this.messenger.shutdown()\n }\n}\n","import type { Ble } from '@animo-id/react-native-ble-didcomm'\nimport type { AgentContext, Logger } from '@credo-ts/core'\nimport { CredoError } from '@credo-ts/core'\nimport type { DidCommOutboundPackage, DidCommOutboundTransport } from '@credo-ts/didcomm'\n\nexport class DidCommBleOutboundTransport implements DidCommOutboundTransport {\n public supportedSchemes: string[] = ['ble']\n private messenger: Ble\n private logger?: Logger\n\n public constructor(messenger: Ble) {\n this.messenger = messenger\n }\n\n public async start(agentContext: AgentContext): Promise<void> {\n this.logger = agentContext.config.logger\n\n this.logger.debug('Starting BLE outbound transport')\n }\n\n public async sendMessage(outboundPackage: DidCommOutboundPackage): Promise<void> {\n const { payload, endpoint } = outboundPackage\n if (!endpoint) {\n throw new CredoError(`Missing endpoint. I don't know how and where to send the message.`)\n }\n\n this.logger?.debug(`Sending outbound message to endpoint '${endpoint}'`, {\n payload,\n })\n\n const serializedMessage = JSON.stringify(payload)\n\n this.logger?.debug('Sending BLE outbound message')\n await this.messenger.sendMessage(serializedMessage)\n }\n\n public async stop(): Promise<void> {\n this.logger?.debug('Stopping BLE outbound transport')\n await this.messenger.shutdown()\n }\n}\n"],"mappings":";;;;AAKA,IAAa,6BAAb,MAA2E;CAOzE,AAAO,YAAY,IAAY,WAAgB,cAA4B;cANpD;AAOrB,OAAK,KAAK,MAAM,MAAM,MAAM;AAC5B,OAAK,YAAY;AACjB,OAAK,eAAe;;CAGtB,MAAa,KAAK,cAA4B,kBAA0D;EACtG,MAAM,oBAAoB,KAAK,UAAU,iBAAiB;AAE1D,eAAa,OAAO,OAAO,MAAM,0CAA0C;AAC3E,QAAM,KAAK,UAAU,YAAY,kBAAkB;;CAGrD,MAAa,QAAuB;AAClC,OAAK,aAAa,OAAO,OAAO,MAAM,+BAA+B;;;;;;ACdzE,IAAa,6BAAb,MAA2E;CAQzE,AAAO,YAAY,WAAgB;0BAPC,CAAC,MAAM;AAQzC,OAAK,YAAY;;CAGnB,MAAa,MAAM,cAA2C;AAC5D,OAAK,SAAS,aAAa,OAAO;AAClC,OAAK,OAAO,MAAM,iCAAiC;AAGnD,OAAK,UAAU,IAAI,2BADD,MAAM,MAAM,EAC2B,KAAK,WAAW,aAAa;EAEtF,MAAM,kBAAkB,OAAO,SAA8B;GAC3D,MAAM,UAAU,KAAK;GAErB,MAAM,kBAAkB,aAAa,kBAAkB,QAAQ,uBAAuB;AAEtF,OAAI;IACF,MAAM,mBAAmB,MAAM,KAAK,MAAM,QAAQ;AAElD,UAAM,gBAAgB,eAAe,kBAAkB,EACrD,SAAS,KAAK,SACf,CAAC;YACK,OAAO;AACd,SAAK,QAAQ,MAAM,6BAA6B,QAAQ;;;AAI5D,OAAK,kBAAkB,KAAK,UAAU,wBAAwB,gBAAgB;EAE9E,MAAM,wBAAwB,OAAO,SAAiC;AACpE,QAAK,QAAQ,MAAM,8BAA8B,EAAE,MAAM,CAAC;AAG1D,GADyB,aAAa,kBAAkB,QAAQ,wBAAwB,CACvE,cAAc,KAAK,QAAQ;;AAG9C,OAAK,wBAAwB,KAAK,UAAU,+BAA+B,sBAAsB;;CAGnG,MAAa,OAAsB;AACjC,OAAK,QAAQ,MAAM,iCAAiC;AAEpD,OAAK,iBAAiB,QAAQ;AAC9B,OAAK,uBAAuB,QAAQ;AACpC,QAAM,KAAK,UAAU,UAAU;;;;;;AC3DnC,IAAa,8BAAb,MAA6E;CAK3E,AAAO,YAAY,WAAgB;0BAJC,CAAC,MAAM;AAKzC,OAAK,YAAY;;CAGnB,MAAa,MAAM,cAA2C;AAC5D,OAAK,SAAS,aAAa,OAAO;AAElC,OAAK,OAAO,MAAM,kCAAkC;;CAGtD,MAAa,YAAY,iBAAwD;EAC/E,MAAM,EAAE,SAAS,aAAa;AAC9B,MAAI,CAAC,SACH,OAAM,IAAI,WAAW,oEAAoE;AAG3F,OAAK,QAAQ,MAAM,yCAAyC,SAAS,IAAI,EACvE,SACD,CAAC;EAEF,MAAM,oBAAoB,KAAK,UAAU,QAAQ;AAEjD,OAAK,QAAQ,MAAM,+BAA+B;AAClD,QAAM,KAAK,UAAU,YAAY,kBAAkB;;CAGrD,MAAa,OAAsB;AACjC,OAAK,QAAQ,MAAM,kCAAkC;AACrD,QAAM,KAAK,UAAU,UAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@credo-ts/didcomm-transport-ble",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"main": "./build/index.mjs",
|
|
5
|
+
"module": "./build/index.mjs",
|
|
6
|
+
"types": "./build/index.d.mts",
|
|
7
|
+
"version": "0.4.0",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./build/index.d.mts",
|
|
11
|
+
"default": "./build/index.mjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"build"
|
|
16
|
+
],
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"license": "Apache-2.0",
|
|
21
|
+
"description": "Bluetooth Low Energy transport for Credo",
|
|
22
|
+
"homepage": "https://github.com/openwallet-foundation/credo-ts-didcomm-ext/tree/main/packages/transport-ble",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/openwallet-foundation/credo-ts-didcomm-ext",
|
|
26
|
+
"directory": "packages/transport-ble"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/openwallet-foundation/credo-ts-didcomm-ext/issues"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@animo-id/react-native-ble-didcomm": "^0.5.1",
|
|
33
|
+
"@credo-ts/core": "^0.7.0",
|
|
34
|
+
"@credo-ts/didcomm": "^0.7.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@animo-id/react-native-ble-didcomm": ">=0.5.1 <=0.9.3",
|
|
38
|
+
"@credo-ts/core": "^0.7.2",
|
|
39
|
+
"@credo-ts/didcomm": "^0.7.2"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsdown --config ./tsdown.config.ts",
|
|
43
|
+
"clean": "rimraf -rf ./build",
|
|
44
|
+
"compile": "tsc -p tsconfig.build.json"
|
|
45
|
+
}
|
|
6
46
|
}
|