@jdr377/mapapp-agent-connector 0.1.0-pre.1 → 0.1.0-pre.10
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 +111 -144
- package/bun.lock +24 -1
- package/dist/chunk-0wyrdcyb.js +17 -0
- package/dist/chunk-3ah5hd7r.js +2 -0
- package/dist/chunk-595sk0qe.js +44 -0
- package/dist/chunk-kk02ctwf.js +3 -0
- package/dist/chunk-v1y901rb.js +3 -0
- package/dist/chunk-x34n6pw4.js +2 -0
- package/dist/chunk-z0hbdn1f.js +3 -0
- package/dist/participant-mcp-server.js +15 -8
- package/distribution.json +89 -34
- package/package.json +4 -3
- package/dist/chunk-0033d0wt.js +0 -2
- package/dist/chunk-ajs19nj9.js +0 -3
- package/dist/chunk-k75c97va.js +0 -17
- package/dist/chunk-r4m45n3d.js +0 -4
- package/dist/chunk-wy5sgkmh.js +0 -3
package/distribution.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": "mapapp-agent-connector-distribution/v1",
|
|
3
3
|
"name": "@jdr377/mapapp-agent-connector",
|
|
4
|
-
"version": "0.1.0-pre.
|
|
4
|
+
"version": "0.1.0-pre.10",
|
|
5
5
|
"runtime": {
|
|
6
6
|
"bun": "1.3.11",
|
|
7
|
+
"requirement": ">=1.3.11 <2.0.0",
|
|
7
8
|
"transport": "stdio",
|
|
8
9
|
"profiles": [
|
|
9
10
|
"direct_wallet_node",
|
|
@@ -14,39 +15,75 @@
|
|
|
14
15
|
"sourceInputs": [
|
|
15
16
|
{
|
|
16
17
|
"path": "scripts/agent/participant-mcp-server.ts",
|
|
17
|
-
"sha256": "
|
|
18
|
+
"sha256": "f90ee70bc87c449c7f2861777343ef7e25e405c6b491d8e90196869e74f78de2"
|
|
18
19
|
},
|
|
19
20
|
{
|
|
20
21
|
"path": "scripts/lib/agentLocalIntentRepository.ts",
|
|
21
22
|
"sha256": "4658662f5ea1f9d264f38e6a4022eff6ac318ee990277da10eca91261105b90d"
|
|
22
23
|
},
|
|
24
|
+
{
|
|
25
|
+
"path": "scripts/lib/agentMessagingLocalStorage.ts",
|
|
26
|
+
"sha256": "8329efc392c932f51b93e79650e24ff74dcadfd1d6b9f1be2d2cf9ce326fae71"
|
|
27
|
+
},
|
|
23
28
|
{
|
|
24
29
|
"path": "scripts/lib/agentMessagingRuntime.ts",
|
|
25
|
-
"sha256": "
|
|
30
|
+
"sha256": "3db82e7f0b0a9b9e4f7f1d0baf7b46c78895ee9c80973782d6961973fc146013"
|
|
26
31
|
},
|
|
27
32
|
{
|
|
28
33
|
"path": "scripts/lib/agentMessagingStorage.ts",
|
|
29
|
-
"sha256": "
|
|
34
|
+
"sha256": "c6ca2f0e5bf7d9a4ac2b1b529d860cd801a0787002a9554f2e50123ac57be434"
|
|
30
35
|
},
|
|
31
36
|
{
|
|
32
37
|
"path": "scripts/lib/agentParticipantHTTP.ts",
|
|
33
|
-
"sha256": "
|
|
38
|
+
"sha256": "d9b68d7f06bb857e92d132e3ce7c8c1ddae61ecec22f0e12844246cbf2770c2a"
|
|
34
39
|
},
|
|
35
40
|
{
|
|
36
41
|
"path": "scripts/lib/agentParticipantRuntime.ts",
|
|
37
|
-
"sha256": "
|
|
42
|
+
"sha256": "c23f57f6bddf8b703c5949c96d6512976dcaea0094d9fda6d56e8a0bfa74a9e7"
|
|
38
43
|
},
|
|
39
44
|
{
|
|
40
45
|
"path": "scripts/lib/agentParticipantSetup.ts",
|
|
41
|
-
"sha256": "
|
|
46
|
+
"sha256": "5e5b1f7fb74e777584c27550ad20debb1bfff48ddb459e0a7c59c7e48956da14"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"path": "server/agent/contract.ts",
|
|
50
|
+
"sha256": "86bd37bf5a5092a1fbb7b3afb5a5b8882ddbd6578ac1260a4ea59c2df69d0f7e"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"path": "server/agent/discoveryHttp.ts",
|
|
54
|
+
"sha256": "03a3b2ac68277fa4eacab31d654e6bec87c5df78b1297a96401e5cbe10fd2847"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"path": "server/agent/discoveryTools.ts",
|
|
58
|
+
"sha256": "b3fae480511d757373604d3564c56da3368aa10ae0afd7ed8478866ac215b920"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"path": "server/agent/geohashTool.ts",
|
|
62
|
+
"sha256": "8dee69324f8aeef915d68dcd6e7981fa9eaf223f1cf8ddecaab959d275636784"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"path": "server/agent/mcp/diagnostics.ts",
|
|
66
|
+
"sha256": "7653dc78e7777f51e4e0774a678aee3b0a1d83f6091512d0afa60abdbc0daf48"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"path": "server/agent/mcp/invoke.ts",
|
|
70
|
+
"sha256": "8468c58d25ca2b98913c7df8dcf6cb376bb4b0b489c128651dc408232a6ca217"
|
|
42
71
|
},
|
|
43
72
|
{
|
|
44
73
|
"path": "server/agent/mcp/participant.ts",
|
|
45
|
-
"sha256": "
|
|
74
|
+
"sha256": "1d067ad92c27fcb6d5a1bf5cc8a476eb8af922aeabc7518f03b38922866bafb6"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"path": "server/agent/mcp/publication.ts",
|
|
78
|
+
"sha256": "2f8fcd0c7414369e883079859ff943c212d8476e0d2d0194393bbc5afd608720"
|
|
46
79
|
},
|
|
47
80
|
{
|
|
48
81
|
"path": "server/agent/onboarding.ts",
|
|
49
|
-
"sha256": "
|
|
82
|
+
"sha256": "7712296a380f8344cfad7b3fe1a892a220575a9ad2a1daacccf668410f3be2e3"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
"path": "server/agent/parser.ts",
|
|
86
|
+
"sha256": "d5046a9f1ece7ce551d8e7cd18f606922a8fab3a78ba6f4d8e529831415a65f9"
|
|
50
87
|
},
|
|
51
88
|
{
|
|
52
89
|
"path": "shared/categories.ts",
|
|
@@ -58,7 +95,11 @@
|
|
|
58
95
|
},
|
|
59
96
|
{
|
|
60
97
|
"path": "shared/freeposting/u12.ts",
|
|
61
|
-
"sha256": "
|
|
98
|
+
"sha256": "98dd20f08f4e7589b3483ad07a496cfe13b3baad9192d3889cc9421305e7a488"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"path": "shared/geohash.ts",
|
|
102
|
+
"sha256": "db35db3427cb3a8fac5b156e9458207d08b9ac5eb0cab0d8dc7183db9eb33254"
|
|
62
103
|
},
|
|
63
104
|
{
|
|
64
105
|
"path": "shared/mediaLimits.ts",
|
|
@@ -66,7 +107,7 @@
|
|
|
66
107
|
},
|
|
67
108
|
{
|
|
68
109
|
"path": "shared/messaging.ts",
|
|
69
|
-
"sha256": "
|
|
110
|
+
"sha256": "48ad165669b17229e574a2d2f09ccacdb40b299260f5bd6a671b54e1ec65b4dd"
|
|
70
111
|
},
|
|
71
112
|
{
|
|
72
113
|
"path": "shared/messagingControl.ts",
|
|
@@ -90,7 +131,7 @@
|
|
|
90
131
|
},
|
|
91
132
|
{
|
|
92
133
|
"path": "src/bitcoin/agentIdentity.ts",
|
|
93
|
-
"sha256": "
|
|
134
|
+
"sha256": "a511dc04a674b0d68b8eed5c4e21fa91400d328a3f06330cc662799bf9a5c037"
|
|
94
135
|
},
|
|
95
136
|
{
|
|
96
137
|
"path": "src/bitcoin/agentMedia.ts",
|
|
@@ -98,27 +139,35 @@
|
|
|
98
139
|
},
|
|
99
140
|
{
|
|
100
141
|
"path": "src/bitcoin/agentMessaging.ts",
|
|
101
|
-
"sha256": "
|
|
142
|
+
"sha256": "c1e13968c3a16f6cb1a5398c0244bb24b4aa3588a63f9686c88eabf4d765b536"
|
|
102
143
|
},
|
|
103
144
|
{
|
|
104
145
|
"path": "src/bitcoin/agentPaidPost.ts",
|
|
105
|
-
"sha256": "
|
|
146
|
+
"sha256": "b1def54f78c9e9decb1aeb1ace46373b994f797d28a0fd77c126dca0ed84e488"
|
|
106
147
|
},
|
|
107
148
|
{
|
|
108
|
-
"path": "src/bitcoin/
|
|
109
|
-
"sha256": "
|
|
149
|
+
"path": "src/bitcoin/agentParticipantBinding.ts",
|
|
150
|
+
"sha256": "a11450a4badbd313161a970c84eba970f51c7e2d62c6c781df030393a6aa8168"
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"path": "src/bitcoin/agentPayment.ts",
|
|
154
|
+
"sha256": "32d0b9abcc9838606d0c7bf6e6eb4b1cb082ee954228f71e7b8adbff3ed1d7b6"
|
|
110
155
|
},
|
|
111
156
|
{
|
|
112
157
|
"path": "src/bitcoin/agentSocialAction.ts",
|
|
113
|
-
"sha256": "
|
|
158
|
+
"sha256": "15db1009f84777e1fa3c97066f9d531c1c7606ee6b2d107e218139a2876748c4"
|
|
114
159
|
},
|
|
115
160
|
{
|
|
116
161
|
"path": "src/bitcoin/agentSponsoredPost.ts",
|
|
117
|
-
"sha256": "
|
|
162
|
+
"sha256": "035b55959fb910ac5427e5922c44d48fc52068596250eaead2cbea41ca2a8f1e"
|
|
118
163
|
},
|
|
119
164
|
{
|
|
120
165
|
"path": "src/bitcoin/agentWalletConnection.ts",
|
|
121
|
-
"sha256": "
|
|
166
|
+
"sha256": "5c813537063577f224372c114abd9caac48eb259c3a4bd02c86e81963bcebe84"
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"path": "src/bitcoin/directBsv.ts",
|
|
170
|
+
"sha256": "398a35474174d9abb768c33b3c1d9e0dd41e03f52bb34b612f8090b42557c001"
|
|
122
171
|
},
|
|
123
172
|
{
|
|
124
173
|
"path": "src/bitcoin/localIntentStore.ts",
|
|
@@ -150,7 +199,7 @@
|
|
|
150
199
|
},
|
|
151
200
|
{
|
|
152
201
|
"path": "src/bitcoin/messaging/messageBoxTransport.ts",
|
|
153
|
-
"sha256": "
|
|
202
|
+
"sha256": "71b2439a71fbbecb9566acca957f9e01decb7e7115492946be6e38c4015cddba"
|
|
154
203
|
},
|
|
155
204
|
{
|
|
156
205
|
"path": "src/bitcoin/messaging/messageHistoryReplica.ts",
|
|
@@ -160,6 +209,10 @@
|
|
|
160
209
|
"path": "src/bitcoin/messaging/sessionCache.ts",
|
|
161
210
|
"sha256": "529823120d74b8d04b179e01f202098016c96e038eb8c5ef509eecab2b88e07a"
|
|
162
211
|
},
|
|
212
|
+
{
|
|
213
|
+
"path": "src/bitcoin/nativeEvidenceRecovery.ts",
|
|
214
|
+
"sha256": "64dd4719c1a856b07cda80be0a6a06cff947d53bccf0dd4466adccb1beaab88c"
|
|
215
|
+
},
|
|
163
216
|
{
|
|
164
217
|
"path": "src/bitcoin/nativeManagedAction.ts",
|
|
165
218
|
"sha256": "d3d89f4776b25794c5f32cbcd5a624c1ec6426fc5fc81d98c325705d9263b441"
|
|
@@ -174,11 +227,11 @@
|
|
|
174
227
|
},
|
|
175
228
|
{
|
|
176
229
|
"path": "src/bitcoin/paidRootPost.ts",
|
|
177
|
-
"sha256": "
|
|
230
|
+
"sha256": "a1c6527092f6dd7852fd05f80240da4ca6a14e0e26eaf2689fe3e63724f8bd35"
|
|
178
231
|
},
|
|
179
232
|
{
|
|
180
233
|
"path": "src/bitcoin/socialV2.ts",
|
|
181
|
-
"sha256": "
|
|
234
|
+
"sha256": "d9ecc70b4aac05d5a82dc3f4b4e916efcd6bb78e17f66a7907e5a4782dbd072e"
|
|
182
235
|
},
|
|
183
236
|
{
|
|
184
237
|
"path": "src/bitcoin/sponsorFlow.ts",
|
|
@@ -186,7 +239,7 @@
|
|
|
186
239
|
},
|
|
187
240
|
{
|
|
188
241
|
"path": "src/bitcoin/sponsoredV2.ts",
|
|
189
|
-
"sha256": "
|
|
242
|
+
"sha256": "5b062c08c00c90cf6652bfb1ca7f87e56ea7908f5d757c08af1f934b69544698"
|
|
190
243
|
},
|
|
191
244
|
{
|
|
192
245
|
"path": "src/bitcoin/transactionIntake.ts",
|
|
@@ -202,18 +255,20 @@
|
|
|
202
255
|
}
|
|
203
256
|
],
|
|
204
257
|
"files": {
|
|
205
|
-
"README.md": "
|
|
206
|
-
"bun.lock": "
|
|
207
|
-
"dist/chunk-
|
|
208
|
-
"dist/chunk-
|
|
258
|
+
"README.md": "a73330da7148be3ff595acfc6ce8e552e9e552d233e80711a7f97e600e35eb83",
|
|
259
|
+
"bun.lock": "70b49fe644812578e2c365f4600fa57b694710f16a8095dc05e4dbc257b3c58a",
|
|
260
|
+
"dist/chunk-0wyrdcyb.js": "1b1d1239d99a370d703f85c4e800e82c0d63b6cfe4e747a2808b38d38e284add",
|
|
261
|
+
"dist/chunk-3ah5hd7r.js": "2fd0080cada3b965dc2ee813056a5f714b0e07789903dd38f95b42975b20a20b",
|
|
262
|
+
"dist/chunk-595sk0qe.js": "700dd1cb7b717ea2b106dc9000b9f11a833b234f909dcdca0f1e7d213f3e405d",
|
|
209
263
|
"dist/chunk-btwmey1h.js": "4e3cec1f9adaea9464cd99ea40ea0b7a693d800040e59540856f6c2b8ff013ee",
|
|
210
264
|
"dist/chunk-c74qq5ek.js": "36c949a5d21a3a2ac2c0e7a1020ebc995f1b665194ea43e8e29244eb8e166257",
|
|
211
265
|
"dist/chunk-e6y2yzbj.js": "4be64909a0536718a794f3d7bd11c4b5af95097ca7295c05cde1394a80027b38",
|
|
212
|
-
"dist/chunk-
|
|
213
|
-
"dist/chunk-
|
|
214
|
-
"dist/chunk-
|
|
215
|
-
"dist/
|
|
216
|
-
"
|
|
266
|
+
"dist/chunk-kk02ctwf.js": "abbe9e7ab08c941ff9d77aecbc7bc7afe5e3c3bbac40b005d6b3240fc1cd0323",
|
|
267
|
+
"dist/chunk-v1y901rb.js": "15dcac0514ced3cec54a8475dfcf6990c300078af1256cea5adb79dc7fc69914",
|
|
268
|
+
"dist/chunk-x34n6pw4.js": "2727168ae85e5aa9f61cced8cf68306f4c80dbfcf21f39416cebd557bb4d4f53",
|
|
269
|
+
"dist/chunk-z0hbdn1f.js": "87a36fa987198195835a5599d13664091a1ad420899e14a4fdf9a0c0f9892193",
|
|
270
|
+
"dist/participant-mcp-server.js": "03d1b36a380276f4b779805576cd271d86c9c02981e3a476250f1b0befd6503b",
|
|
271
|
+
"package.json": "837ee47ee6d22bbc08920a470efab4152ee9f90c45302bf5a7775577908c9b3b"
|
|
217
272
|
},
|
|
218
273
|
"dependencies": {
|
|
219
274
|
"@1sat/actions": "0.0.224",
|
|
@@ -228,6 +283,7 @@
|
|
|
228
283
|
"@bsv/wallet-toolbox-client": "npm:@bopen-io/wallet-toolbox-client@2.6.2-brc153.5",
|
|
229
284
|
"@jdr377/message-box-store": "0.1.0-beta.0",
|
|
230
285
|
"@jsquash/webp": "1.5.0",
|
|
286
|
+
"@modelcontextprotocol/client": "2.3.1",
|
|
231
287
|
"@modelcontextprotocol/server": "2.3.1",
|
|
232
288
|
"mediabunny": "1.52.3",
|
|
233
289
|
"zod": "4.6.5"
|
|
@@ -237,7 +293,6 @@
|
|
|
237
293
|
"remainingReleaseGates": [
|
|
238
294
|
"final_qualification_of_this_artifact",
|
|
239
295
|
"authorized_publication",
|
|
240
|
-
"
|
|
241
|
-
"independent_public_onboarding"
|
|
296
|
+
"matching_public_instructions"
|
|
242
297
|
]
|
|
243
298
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jdr377/mapapp-agent-connector",
|
|
3
|
-
"version": "0.1.0-pre.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0-pre.10",
|
|
4
|
+
"description": "Local MCP for MapApp discovery, participant wallet actions and private messaging",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"engines": {
|
|
9
|
-
"bun": "1.3.11"
|
|
9
|
+
"bun": ">=1.3.11 <2.0.0"
|
|
10
10
|
},
|
|
11
11
|
"bin": {
|
|
12
12
|
"mapapp-participant": "dist/participant-mcp-server.js"
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"@bsv/wallet-toolbox-client": "npm:@bopen-io/wallet-toolbox-client@2.6.2-brc153.5",
|
|
31
31
|
"@jdr377/message-box-store": "0.1.0-beta.0",
|
|
32
32
|
"@jsquash/webp": "1.5.0",
|
|
33
|
+
"@modelcontextprotocol/client": "2.3.1",
|
|
33
34
|
"@modelcontextprotocol/server": "2.3.1",
|
|
34
35
|
"mediabunny": "1.52.3",
|
|
35
36
|
"zod": "4.6.5"
|
package/dist/chunk-0033d0wt.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{createParticipantAuthorityReader,openAgentParticipantRuntime,parseParticipantAuthority,participantExternalMetadataSchema,participantMetadataSchema}from"./chunk-k75c97va.js";import"./chunk-e6y2yzbj.js";import"./chunk-wy5sgkmh.js";import"./chunk-btwmey1h.js";export{participantMetadataSchema,participantExternalMetadataSchema,parseParticipantAuthority,openAgentParticipantRuntime,createParticipantAuthorityReader};
|
package/dist/chunk-ajs19nj9.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{createAgentWalletConnectionInspector,createParticipantHTTPWallet,exportWalletDataZip,inspectWalletDataZip,openAgentLocalIntentRepository,parseParticipantAuthority,participantMetadataSchema,restoreWalletDataZip}from"./chunk-k75c97va.js";import"./chunk-e6y2yzbj.js";import"./chunk-wy5sgkmh.js";import"./chunk-btwmey1h.js";import{mkdir,open,readFile,rename,stat,copyFile}from"fs/promises";import{basename,join,resolve}from"path";import{constants}from"fs";import{createContext,computeBapId,resolveBapId}from"@1sat/actions";import{createNodeWallet}from"@1sat/wallet-node";import{PrivateKey}from"@bsv/sdk";var schema="mapapp-participant-setup/v1";class ParticipantSetupError extends Error{code;constructor(code){super(code);this.code=code}}function participantDeployment(value){try{const url=new URL(value);if(url.protocol!=="https:"||url.username||url.password||url.search||url.hash||url.pathname!=="/")throw new Error;return url.origin}catch{throw new ParticipantSetupError("setup_deployment_invalid")}}async function protectedWrite(filename,bytes,replace=false){const temporary=replace?`${filename}.${crypto.randomUUID()}.pending`:filename;const file=await open(temporary,"wx",384);try{await file.writeFile(bytes);await file.sync()}finally{await file.close()}if(replace)await rename(temporary,filename)}async function readParticipantSetup(directory){const path=join(resolve(directory),"setup.json");if((await stat(path)).size>4096)throw new ParticipantSetupError("setup_state_invalid");const value=JSON.parse(await readFile(path,"utf8"));if(value.schema!==schema||!["creating","restore_started","wallet_ready"].includes(value.phase)||!/^(02|03)[0-9a-f]{64}$/u.test(value.identityKey))throw new ParticipantSetupError("setup_state_invalid");return value}async function setupParticipantWallet(options){const directory=resolve(options.walletDirectory);const deployment=participantDeployment(options.deployment);let created=false;try{await mkdir(directory,{mode:448});created=true}catch(error){if(error.code!=="EEXIST")throw error}if(!created&&options.restore)throw new ParticipantSetupError("restore_requires_new_directory");if(created){const suppliedRoot=options.restore?(await boundedFile(options.restore.rootFile,128)).toString().trim():null;const key=suppliedRoot?PrivateKey.fromWif(suppliedRoot):PrivateKey.fromRandom();const meta2={chain:"main",identityKey:key.toPublicKey().toString(),storageIdentityKey:crypto.randomUUID(),servicesBaseUrl:`${deployment}/api/bitcoin/wallet-services`};const restoredAuthority=options.restore?parseParticipantAuthority(JSON.parse((await boundedFile(options.restore.authorityFile,4096)).toString())):null;if(options.restore){await inspectWalletDataZip(new Uint8Array(await boundedFile(options.restore.backupFile,512*1024*1024)),meta2);const operations=await boundedFile(options.restore.operationsFile,256*1024*1024);if(!operations.subarray(0,16).equals(Buffer.from("SQLite format 3\x00")))throw new ParticipantSetupError("restore_operations_invalid");if(await stat(options.restore.operationsFile+"-wal").then((info)=>info.size>0,()=>false))throw new ParticipantSetupError("restore_operations_not_checkpointed")}await protectedWrite(join(directory,"setup.json"),JSON.stringify({schema,phase:"creating",identityKey:meta2.identityKey,servicesBaseUrl:meta2.servicesBaseUrl}));await protectedWrite(join(directory,"wallet.json"),JSON.stringify(meta2));await protectedWrite(join(directory,"root.wif"),(suppliedRoot??key.toWif())+`
|
|
3
|
-
`);await protectedWrite(join(directory,"participant-authority.json"),JSON.stringify(restoredAuthority??{schema:"mapapp-participant-authority/v1",connectionId:`participant-${crypto.randomUUID()}`,callerId:`owner-${crypto.randomUUID()}`,originator:new URL(deployment).hostname,revision:"initial-denied",publishExactText:false,fullRootSpendingAuthorized:false}));if(options.restore)await copyFile(options.restore.operationsFile,join(directory,"agent-intents.sqlite"),constants.COPYFILE_EXCL)}const state=await readParticipantSetup(directory).catch(()=>{throw new ParticipantSetupError("setup_existing_directory_unrecognized")});if(state.servicesBaseUrl!==`${deployment}/api/bitcoin/wallet-services`)throw new ParticipantSetupError("setup_deployment_changed");if(state.phase==="restore_started")throw new ParticipantSetupError("restore_outcome_unknown");const meta=participantMetadataSchema.parse(JSON.parse((await boundedFile(join(directory,"wallet.json"),4096)).toString()));if(meta.identityKey!==state.identityKey||meta.servicesBaseUrl!==state.servicesBaseUrl)throw new ParticipantSetupError("setup_identity_changed");const root=PrivateKey.fromWif((await boundedFile(join(directory,"root.wif"),128)).toString().trim());if(root.toPublicKey().toString()!==meta.identityKey)throw new ParticipantSetupError("setup_identity_changed");const authority=parseParticipantAuthority(JSON.parse((await boundedFile(join(directory,"participant-authority.json"),4096)).toString()));const owned=openAgentLocalIntentRepository(join(directory,"agent-intents.sqlite"));let runtime;try{runtime=await createNodeWallet({privateKey:root,chain:"main",storageIdentityKey:meta.storageIdentityKey,storage:{provider:"bun-sqlite",filename:join(directory,"wallet.sqlite")},servicesBaseUrl:meta.servicesBaseUrl,skipInitialMonitor:true,backups:[],feeModel:{model:"sat/kb",value:100}});if((await runtime.wallet.getPublicKey({identityKey:true})).publicKey!==meta.identityKey||(await runtime.wallet.getNetwork({})).network!=="mainnet")throw new ParticipantSetupError("setup_wallet_binding_changed");if(options.restore){await protectedWrite(join(directory,"setup.json"),JSON.stringify({...state,phase:"restore_started"}),true);await restoreWalletDataZip(runtime.storage,new Uint8Array(await boundedFile(options.restore.backupFile,512*1024*1024)),meta,{assertTargetFresh:async()=>{if(!created)throw new ParticipantSetupError("restore_requires_new_directory")}})}const context=createContext(runtime.wallet,{services:runtime.services,dataDir:directory,chain:"main"});const bapId=await computeBapId(context),published=await resolveBapId(context);let recoveryArchive=state.recoveryArchive;if(state.phase==="wallet_ready"){if(!recoveryArchive||basename(recoveryArchive)!==recoveryArchive)throw new ParticipantSetupError("setup_recovery_archive_invalid");await inspectWalletDataZip(new Uint8Array(await boundedFile(join(directory,recoveryArchive),512*1024*1024)),meta)}if(state.phase!=="wallet_ready"){const archive=await exportWalletDataZip(runtime.storage,meta,{maxChunks:20});recoveryArchive=`wallet-data-setup-${crypto.randomUUID()}.zip`;await protectedWrite(join(directory,recoveryArchive),archive.bytes);await protectedWrite(join(directory,"setup.json"),JSON.stringify({...state,phase:"wallet_ready",recoveryArchive}),true)}return{schema,state:"wallet_ready",reused:!created,network:"mainnet",identityKey:meta.identityKey,bapId,identityPublication:published?"wallet_observed":"not_published",publicIdentityObservation:"not_checked",recovery:{rootFile:"root.wif",walletDataZip:recoveryArchive,operationStore:"agent-intents.sqlite"},authorityFile:"participant-authority.json",actionAuthority:created&&!options.restore?"denied_by_default":"retained_participant_policy",authorityRevision:authority.revision,next:published?"check_readiness":"authorize_sponsored_identity"}}finally{try{await runtime?.destroy()}finally{owned.close()}}}async function connectParticipantWallet(options){const directory=resolve(options.walletDirectory),deployment=participantDeployment(options.deployment);const originator=new URL(deployment).hostname;const authority={schema:"mapapp-participant-authority/v1",connectionId:`participant-${crypto.randomUUID()}`,callerId:`owner-${crypto.randomUUID()}`,originator,revision:"initial-denied",publishExactText:false,fullRootSpendingAuthorized:false,walletActionsAuthorized:false};const wallet=createParticipantHTTPWallet(options.walletEndpoint,originator);const inspector=createAgentWalletConnectionInspector({wallet,binding:{connectionId:authority.connectionId,callerId:authority.callerId,originator,expectedIdentityKey:options.identityKey,expectedNetwork:"mainnet",route:"existing_brc100",declaredAuthority:"provider"}});const observed=await inspector.inspect(authority.callerId);if(observed.state!=="ready")throw new ParticipantSetupError(`setup_provider_${observed.state}`);await mkdir(directory,{mode:448});await protectedWrite(join(directory,"wallet.json"),JSON.stringify({transport:"brc100_http",chain:"main",identityKey:options.identityKey,servicesBaseUrl:`${deployment}/api/bitcoin/wallet-services`,walletEndpoint:options.walletEndpoint}));await protectedWrite(join(directory,"participant-authority.json"),JSON.stringify(authority));const owned=openAgentLocalIntentRepository(join(directory,"agent-intents.sqlite"));owned.close();return{schema,state:"provider_bound",route:"existing_brc100",identityKey:options.identityKey,network:"mainnet",actionAuthority:"denied_by_default",backup:"provider_owned",authorityFile:"participant-authority.json",next:"check_readiness"}}async function boundedFile(filename,maximum){const info=await stat(filename);if(!info.isFile()||info.size<1||info.size>maximum)throw new ParticipantSetupError("setup_file_invalid");const bytes=await readFile(filename);if(bytes.length>maximum)throw new ParticipantSetupError("setup_file_invalid");return bytes}export{setupParticipantWallet,readParticipantSetup,participantDeployment,connectParticipantWallet,ParticipantSetupError};
|