@jdr377/mapapp-agent-connector 0.1.0-pre.12 → 0.1.0-pre.14
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 +9 -9
- package/dist/{chunk-28ykvb04.js → chunk-355wg846.js} +5 -5
- package/dist/{chunk-wd3q2byr.js → chunk-ab7h8qq0.js} +1 -1
- package/dist/{chunk-zqcj030q.js → chunk-d722pj7f.js} +1 -1
- package/dist/{chunk-w6cmjk3w.js → chunk-jr7dhw6k.js} +1 -1
- package/dist/chunk-mb8a3fs5.js +3 -0
- package/dist/{chunk-1c876c9w.js → chunk-n19v6f2m.js} +1 -1
- package/dist/chunk-tssaj9jc.js +17 -0
- package/dist/participant-mcp-server.js +5 -5
- package/distribution.json +42 -22
- package/package.json +1 -1
- package/dist/chunk-v1y901rb.js +0 -3
- package/dist/chunk-yw2vsz4v.js +0 -17
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{participantErrorDiagnostic,silenceParticipantConsole}from"./chunk-
|
|
3
|
+
import{participantErrorDiagnostic,silenceParticipantConsole}from"./chunk-jr7dhw6k.js";import{__require}from"./chunk-btwmey1h.js";import{StdioServerTransport}from"@modelcontextprotocol/server/stdio";var invocationUsage=`Tools: mapapp-participant tools --wallet-dir <existing-state> [--tool <name>]
|
|
4
4
|
Call: mapapp-participant call --wallet-dir <existing-state> --tool <name> [--arguments-file <utf8-json-file-or->]
|
|
5
5
|
Omit --arguments-file for {}. Use - to read JSON from stdin. Calls use the same MCP tools; retain original operation IDs after uncertainty.
|
|
6
6
|
`;var usage=`Usage: mapapp-participant --wallet-dir <existing-protected-wallet>
|
|
@@ -10,10 +10,10 @@ Connect: mapapp-participant connect --wallet-dir <new-connector-directory> --dep
|
|
|
10
10
|
First setup/connect/restore: the final destination must not already exist, even empty. Keep the MCP host/client session open until awaited calls finish.
|
|
11
11
|
One local stdio MCP provides discovery, paid/sponsored/social actions and private messaging. No HTTP listener. Delegation belongs to the user and agent; connected wallets enforce their own permissions. Preserve original operation IDs after uncertainty. Read /developers?guide=agent-setup.
|
|
12
12
|
`;function readParticipantSetupCommand(args){if(!["setup","restore","connect"].includes(args[0]??""))return null;const fields={};const allowed=args[0]==="restore"?["--wallet-dir","--deployment","--root-file","--backup-file","--connection-file","--operations-file"]:args[0]==="connect"?["--wallet-dir","--deployment","--wallet-endpoint","--identity-key"]:["--wallet-dir","--deployment"];for(let i=1;i<args.length;i+=2){const key=args[i],value=args[i+1];if(!allowed.includes(key)||fields[key]||!value||value.startsWith("--"))throw new Error("participant_configuration_invalid");fields[key]=value}if(allowed.some((key)=>!fields[key]))throw new Error("participant_configuration_invalid");return{walletDirectory:fields["--wallet-dir"],deployment:fields["--deployment"],...args[0]==="connect"?{walletEndpoint:fields["--wallet-endpoint"],identityKey:fields["--identity-key"]}:{},...args[0]==="restore"?{restore:{rootFile:fields["--root-file"],backupFile:fields["--backup-file"],connectionFile:fields["--connection-file"],operationsFile:fields["--operations-file"]}}:{}}}function readParticipantMcpConfig(args){if(args.length===1&&["--help","-h"].includes(args[0]))return null;let walletDirectory;let connectionFile;const seen=new Set;for(let i=0;i<args.length;i++){const key=args[i];if(seen.has(key))throw new Error("participant_configuration_invalid");seen.add(key);const value=args[++i];if(!value||value.startsWith("--"))throw new Error("participant_configuration_invalid");if(key==="--wallet-dir")walletDirectory=value;else if(key==="--connection-file")connectionFile=value;else throw new Error("participant_configuration_invalid")}if(!walletDirectory)throw new Error("participant_configuration_invalid");return{walletDirectory,...connectionFile?{connectionFile}:{}}}if(import.meta.main){silenceParticipantConsole();let runtime;let participant;let closing;const setupMode=["setup","restore","connect"].includes(process.argv[2]??"");const invocationMode=["tools","call"].includes(process.argv[2]??"");const close=()=>closing??=(async()=>{try{await participant?.close()}finally{await runtime?.close()}})();const closeInvocation=async()=>{try{await close()}catch{process.stderr.write(JSON.stringify({error:participantErrorDiagnostic(null,"participant_close_unavailable")})+`
|
|
13
|
-
`);process.exitCode=1}};try{const args=process.argv.slice(2);const invocation=invocationMode?(await import("./chunk-
|
|
14
|
-
`)}else if(!config)process.stderr.write(usage+invocationUsage);else{const[{openAgentParticipantRuntime},{createMapAppParticipantServer,PARTICIPANT_MCP_MAX_MESSAGE_BYTES}]=await Promise.all([import("./chunk-
|
|
15
|
-
`);process.exit(1)})};process.once("SIGINT",stop);process.once("SIGTERM",stop);if(invocation){try{const outcome=await(await import("./chunk-
|
|
16
|
-
`);process.exitCode="isError"in outcome&&outcome.isError?1:0}finally{await closeInvocation();process.off("SIGINT",stop);process.off("SIGTERM",stop)}}else{process.stdin.once("end",stop);await participant.server.connect(new StdioServerTransport(process.stdin,process.stdout,{maxBufferSize:PARTICIPANT_MCP_MAX_MESSAGE_BYTES}))}}}catch(error){if(invocationMode){process.stdout.write(JSON.stringify((await import("./chunk-
|
|
13
|
+
`);process.exitCode=1}};try{const args=process.argv.slice(2);const invocation=invocationMode?(await import("./chunk-d722pj7f.js")).readParticipantInvocation(args):null;const setup=readParticipantSetupCommand(args);const config=setup?null:readParticipantMcpConfig(invocation?.walletArgs??args);if(setup){const{setupParticipantWallet,connectParticipantWallet}=await import("./chunk-ab7h8qq0.js");const outcome=setup.walletEndpoint&&setup.identityKey?await connectParticipantWallet({...setup,walletEndpoint:setup.walletEndpoint,identityKey:setup.identityKey}):await setupParticipantWallet(setup);process.stdout.write(JSON.stringify(outcome)+`
|
|
14
|
+
`)}else if(!config)process.stderr.write(usage+invocationUsage);else{const[{openAgentParticipantRuntime},{createMapAppParticipantServer,PARTICIPANT_MCP_MAX_MESSAGE_BYTES}]=await Promise.all([import("./chunk-n19v6f2m.js"),import("./chunk-355wg846.js")]);const invocationArgs=invocation?await(await import("./chunk-d722pj7f.js")).readInvocationArguments(invocation.argumentsFile,PARTICIPANT_MCP_MAX_MESSAGE_BYTES):undefined;runtime=await openAgentParticipantRuntime(config);participant=createMapAppParticipantServer(runtime);const stop=()=>{close().then(()=>process.exit(invocation?130:0),()=>{process.stderr.write(JSON.stringify({error:participantErrorDiagnostic(null,"participant_close_unavailable")})+`
|
|
15
|
+
`);process.exit(1)})};process.once("SIGINT",stop);process.once("SIGTERM",stop);if(invocation){try{const outcome=await(await import("./chunk-d722pj7f.js")).invokeParticipant(participant.server,invocation,invocationArgs);process.stdout.write(JSON.stringify(outcome)+`
|
|
16
|
+
`);process.exitCode="isError"in outcome&&outcome.isError?1:0}finally{await closeInvocation();process.off("SIGINT",stop);process.off("SIGTERM",stop)}}else{process.stdin.once("end",stop);await participant.server.connect(new StdioServerTransport(process.stdin,process.stdout,{maxBufferSize:PARTICIPANT_MCP_MAX_MESSAGE_BYTES}))}}}catch(error){if(invocationMode){process.stdout.write(JSON.stringify((await import("./chunk-d722pj7f.js")).invocationFailure(error))+`
|
|
17
17
|
`);await closeInvocation();process.exitCode=1}else{const diagnostic=participantErrorDiagnostic(error,setupMode?"participant_setup_unavailable":"participant_startup_unavailable");if(setupMode){process.stdout.write(JSON.stringify({state:"blocked",reason:diagnostic.code,diagnostic})+`
|
|
18
18
|
`)}process.stderr.write(JSON.stringify({error:diagnostic})+`
|
|
19
19
|
`);await closeInvocation();process.exitCode=1}}}export{readParticipantSetupCommand,readParticipantMcpConfig};
|
package/distribution.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.14",
|
|
5
5
|
"runtime": {
|
|
6
6
|
"bun": "1.3.11",
|
|
7
7
|
"requirement": ">=1.3.11 <2.0.0",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
41
|
"path": "scripts/lib/agentParticipantRuntime.ts",
|
|
42
|
-
"sha256": "
|
|
42
|
+
"sha256": "0f2ff3900379555e4b233736892fcd6d0ef33771422c668bb132c28c8faaae8b"
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
45
|
"path": "scripts/lib/agentParticipantSetup.ts",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
},
|
|
64
64
|
{
|
|
65
65
|
"path": "server/agent/mcp/diagnostics.ts",
|
|
66
|
-
"sha256": "
|
|
66
|
+
"sha256": "6cbd4ce0535da3d3f91ed42aa6a6e658f53b1823436158e84c9495737d524dc1"
|
|
67
67
|
},
|
|
68
68
|
{
|
|
69
69
|
"path": "server/agent/mcp/invoke.ts",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
},
|
|
72
72
|
{
|
|
73
73
|
"path": "server/agent/mcp/participant.ts",
|
|
74
|
-
"sha256": "
|
|
74
|
+
"sha256": "8be16e4c4044e7a8a85fb46157645d12a83ee2d1856c933351e51cf1cc700af5"
|
|
75
75
|
},
|
|
76
76
|
{
|
|
77
77
|
"path": "server/agent/mcp/publication.ts",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
},
|
|
80
80
|
{
|
|
81
81
|
"path": "server/agent/onboarding.ts",
|
|
82
|
-
"sha256": "
|
|
82
|
+
"sha256": "9137910fc77a88336e8cb3f157123a2b33c258b716d932eacfa3840ee58b0870"
|
|
83
83
|
},
|
|
84
84
|
{
|
|
85
85
|
"path": "server/agent/parser.ts",
|
|
@@ -131,7 +131,11 @@
|
|
|
131
131
|
},
|
|
132
132
|
{
|
|
133
133
|
"path": "src/bitcoin/agentIdentity.ts",
|
|
134
|
-
"sha256": "
|
|
134
|
+
"sha256": "fb9ed55638c5163ff73f590f1fc96a4d2450c8b50e96c8da57d8ef879d75fc04"
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"path": "src/bitcoin/agentLocks.ts",
|
|
138
|
+
"sha256": "0bbf5a8527f06ca212dbd2f64b8eaea581e29bde33284742354f8d09f611bdfc"
|
|
135
139
|
},
|
|
136
140
|
{
|
|
137
141
|
"path": "src/bitcoin/agentMedia.ts",
|
|
@@ -143,7 +147,7 @@
|
|
|
143
147
|
},
|
|
144
148
|
{
|
|
145
149
|
"path": "src/bitcoin/agentPaidPost.ts",
|
|
146
|
-
"sha256": "
|
|
150
|
+
"sha256": "6e54037d69a4f906c7a477c2b52345696b8ed0ce0397d25b108d1f5595715c02"
|
|
147
151
|
},
|
|
148
152
|
{
|
|
149
153
|
"path": "src/bitcoin/agentParticipantBinding.ts",
|
|
@@ -151,27 +155,35 @@
|
|
|
151
155
|
},
|
|
152
156
|
{
|
|
153
157
|
"path": "src/bitcoin/agentPayment.ts",
|
|
154
|
-
"sha256": "
|
|
158
|
+
"sha256": "04a81690e10228dbac3aa098ba5555d03d310713e31d4de97a9fded61ea5e091"
|
|
155
159
|
},
|
|
156
160
|
{
|
|
157
161
|
"path": "src/bitcoin/agentSocialAction.ts",
|
|
158
|
-
"sha256": "
|
|
162
|
+
"sha256": "1aeb1da1dcdf22acf6bd3199920996596141a66c3a46d822bc482710f4267620"
|
|
159
163
|
},
|
|
160
164
|
{
|
|
161
165
|
"path": "src/bitcoin/agentSponsoredPost.ts",
|
|
162
|
-
"sha256": "
|
|
166
|
+
"sha256": "2a2e0e6812367e719b3b870919d6f4cbc9d90a8533d7775f2cc35f91f355efd1"
|
|
163
167
|
},
|
|
164
168
|
{
|
|
165
169
|
"path": "src/bitcoin/agentWalletConnection.ts",
|
|
166
170
|
"sha256": "5c813537063577f224372c114abd9caac48eb259c3a4bd02c86e81963bcebe84"
|
|
167
171
|
},
|
|
172
|
+
{
|
|
173
|
+
"path": "src/bitcoin/boundedLockUnlock.ts",
|
|
174
|
+
"sha256": "847e5a53380050ed2fd80c043550b2a76145de34afd6ef7898b8057b982b66af"
|
|
175
|
+
},
|
|
168
176
|
{
|
|
169
177
|
"path": "src/bitcoin/directBsv.ts",
|
|
170
178
|
"sha256": "398a35474174d9abb768c33b3c1d9e0dd41e03f52bb34b612f8090b42557c001"
|
|
171
179
|
},
|
|
172
180
|
{
|
|
173
181
|
"path": "src/bitcoin/localIntentStore.ts",
|
|
174
|
-
"sha256": "
|
|
182
|
+
"sha256": "5149377dac6ce833caacd5d4276be598efa44096fb45f2b6d8b010672e242b21"
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
"path": "src/bitcoin/locks.ts",
|
|
186
|
+
"sha256": "e8195f00fd3bdff08405da1b423827803892fe17d27ed2e0149c062ab3ffec4f"
|
|
175
187
|
},
|
|
176
188
|
{
|
|
177
189
|
"path": "src/bitcoin/messaging/coordinator.ts",
|
|
@@ -211,7 +223,7 @@
|
|
|
211
223
|
},
|
|
212
224
|
{
|
|
213
225
|
"path": "src/bitcoin/nativeEvidenceRecovery.ts",
|
|
214
|
-
"sha256": "
|
|
226
|
+
"sha256": "2426b2e0b76d363b0b06f3bc9d1b724b74dbe9a58800dca5243babe242bde6fd"
|
|
215
227
|
},
|
|
216
228
|
{
|
|
217
229
|
"path": "src/bitcoin/nativeManagedAction.ts",
|
|
@@ -229,6 +241,10 @@
|
|
|
229
241
|
"path": "src/bitcoin/paidRootPost.ts",
|
|
230
242
|
"sha256": "a1c6527092f6dd7852fd05f80240da4ca6a14e0e26eaf2689fe3e63724f8bd35"
|
|
231
243
|
},
|
|
244
|
+
{
|
|
245
|
+
"path": "src/bitcoin/signedBeefRelay.ts",
|
|
246
|
+
"sha256": "e9bf9698eaf8b5e27c7d978e6f3b8d908f1a303fdd51eca7cf52e09666aaa088"
|
|
247
|
+
},
|
|
232
248
|
{
|
|
233
249
|
"path": "src/bitcoin/socialV2.ts",
|
|
234
250
|
"sha256": "d9ecc70b4aac05d5a82dc3f4b4e916efcd6bb78e17f66a7907e5a4782dbd072e"
|
|
@@ -249,26 +265,30 @@
|
|
|
249
265
|
"path": "src/bitcoin/walletDataZip.ts",
|
|
250
266
|
"sha256": "811d1f52359b6a42ed6f1acd1d9f04f52789b01282bdec9900f94297b879a09c"
|
|
251
267
|
},
|
|
268
|
+
{
|
|
269
|
+
"path": "src/bitcoin/walletLocks.ts",
|
|
270
|
+
"sha256": "dcedad129f5f465b79f5a71d5ffec9c337163d363c3ec471522e6459761d4ee2"
|
|
271
|
+
},
|
|
252
272
|
{
|
|
253
273
|
"path": "src/bitcoin/walletPortability.ts",
|
|
254
274
|
"sha256": "b23ed77aedf9e38505fe7141be862b673b58de4621b82de40ce8775dc113c0ec"
|
|
255
275
|
}
|
|
256
276
|
],
|
|
257
277
|
"files": {
|
|
258
|
-
"README.md": "
|
|
278
|
+
"README.md": "7871f555a9b85793ae4af43dbb03ed46e3b454813fa1bd3016271e585e1a04c7",
|
|
259
279
|
"bun.lock": "70b49fe644812578e2c365f4600fa57b694710f16a8095dc05e4dbc257b3c58a",
|
|
260
|
-
"dist/chunk-
|
|
261
|
-
"dist/chunk-
|
|
280
|
+
"dist/chunk-355wg846.js": "709795dda2e5a028f8b0c47ff726b3a98ea6372d67efca59a7e27dc6fcc44ea9",
|
|
281
|
+
"dist/chunk-ab7h8qq0.js": "423080c37744c99488de594cb54280d1f82a1ba247d726cc02d7764830c0e3e7",
|
|
262
282
|
"dist/chunk-btwmey1h.js": "4e3cec1f9adaea9464cd99ea40ea0b7a693d800040e59540856f6c2b8ff013ee",
|
|
263
283
|
"dist/chunk-c74qq5ek.js": "36c949a5d21a3a2ac2c0e7a1020ebc995f1b665194ea43e8e29244eb8e166257",
|
|
284
|
+
"dist/chunk-d722pj7f.js": "336ba703c6c160964f01555607abef971bde2ce2c2c1382f62c68bc319a3fb0e",
|
|
264
285
|
"dist/chunk-e6y2yzbj.js": "4be64909a0536718a794f3d7bd11c4b5af95097ca7295c05cde1394a80027b38",
|
|
265
|
-
"dist/chunk-
|
|
266
|
-
"dist/chunk-
|
|
267
|
-
"dist/chunk-
|
|
268
|
-
"dist/chunk-
|
|
269
|
-
"dist/
|
|
270
|
-
"
|
|
271
|
-
"package.json": "7bd94ca671845b540dfa5ba8ccc445b76c2b9e20b661d18946b02340f6020826"
|
|
286
|
+
"dist/chunk-jr7dhw6k.js": "3f47b1533e8db8572cc401d34e7d0bf58d52cf662d01ac98a256e833c932b575",
|
|
287
|
+
"dist/chunk-mb8a3fs5.js": "387a80cf141a2f6039d615f98f4ea452f147d8dcf459e0c1fcded70d4aecc8db",
|
|
288
|
+
"dist/chunk-n19v6f2m.js": "a00e3086e07b3282e9390805e16274b2789b886ca0c7f929e7da7ebd8dd07428",
|
|
289
|
+
"dist/chunk-tssaj9jc.js": "85aca370f9c2d5817f2190ccc342d4349caaf3eb967d0cb97ccfdd5f9262a85c",
|
|
290
|
+
"dist/participant-mcp-server.js": "919dae931df2ff9629b549f92b00a53bf1cebff407902d75c89b1638d0c94754",
|
|
291
|
+
"package.json": "cdfe938e4a63eeb2c78939bfc89ab92095a39916e82204a816acbe5120823bc6"
|
|
272
292
|
},
|
|
273
293
|
"dependencies": {
|
|
274
294
|
"@1sat/actions": "0.0.224",
|
package/package.json
CHANGED
package/dist/chunk-v1y901rb.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{__require}from"./chunk-btwmey1h.js";var POST_GEOHASH_MIN_PRECISION=8;var POST_GEOHASH_MAX_PRECISION=16;var POST_GEOHASH_DEFAULT_PRECISION=9;var POST_GEOHASH_PATTERN=/^[0123456789bcdefghjkmnpqrstuvwxyz]{8,16}$/;var BASE32="0123456789bcdefghjkmnpqrstuvwxyz";function encodeGeohash(lat,lng,precision=6){const safePrecision=Math.max(4,Math.min(16,Math.trunc(precision)));const latRange=[-90,90];const lngRange=[-180,180];const bits=[16,8,4,2,1];let isEven=true;let bit=0;let ch=0;let geohash="";const safeLat=clampFinite(lat,-90,90);const safeLng=clampFinite(lng,-180,180);while(geohash.length<safePrecision){if(isEven){const mid=(lngRange[0]+lngRange[1])/2;if(safeLng>=mid){ch|=bits[bit]??0;lngRange[0]=mid}else{lngRange[1]=mid}}else{const mid=(latRange[0]+latRange[1])/2;if(safeLat>=mid){ch|=bits[bit]??0;latRange[0]=mid}else{latRange[1]=mid}}isEven=!isEven;if(bit<4){bit+=1}else{geohash+=BASE32[ch]??"0";bit=0;ch=0}}return geohash}function geohashBounds(geohash){const safeGeohash=geohash.trim().toLowerCase();if(!safeGeohash)return null;const latRange=[-90,90];const lngRange=[-180,180];let isEven=true;for(const character of safeGeohash){const value=BASE32.indexOf(character);if(value<0)return null;for(const mask of[16,8,4,2,1]){if(isEven){bisectRange(lngRange,(value&mask)!==0)}else{bisectRange(latRange,(value&mask)!==0)}isEven=!isEven}}return{west:lngRange[0],south:latRange[0],east:lngRange[1],north:latRange[1]}}function bisectRange(range,useUpperHalf){const mid=(range[0]+range[1])/2;if(useUpperHalf){range[0]=mid}else{range[1]=mid}}function clampFinite(value,min,max){if(value===Number.POSITIVE_INFINITY)return max;if(value===Number.NEGATIVE_INFINITY)return min;if(!Number.isFinite(value))return min;return Math.min(max,Math.max(min,value))}var MEDIA_RELAY_SAFE_MAX_BYTES=99*1024;function readWebpDimensions(bytes){if(bytes.length<20||text4(bytes,0)!=="RIFF"||text4(bytes,8)!=="WEBP"||u32(bytes,4)+8!==bytes.length)return null;let offset=12;let extended=null;let image=null;while(offset<bytes.length){if(offset+8>bytes.length)return null;const kind=text4(bytes,offset);const length=u32(bytes,offset+4);const payload=offset+8;const end=payload+length;const paddedEnd=end+(length&1);if(end>bytes.length||paddedEnd>bytes.length)return null;if(!extended&&kind==="VP8X"){if(length!==10)return null;extended={width:1+u24(bytes,payload+4),height:1+u24(bytes,payload+7)}}else if(!image&&kind==="VP8 "){if(length<10||bytes[payload+3]!==157||bytes[payload+4]!==1||bytes[payload+5]!==42)return null;image={width:(bytes[payload+6]|bytes[payload+7]<<8)&16383,height:(bytes[payload+8]|bytes[payload+9]<<8)&16383}}else if(!image&&kind==="VP8L"){if(length<5||bytes[payload]!==47)return null;const bits=u32(bytes,payload+1);image={width:1+(bits&16383),height:1+(bits>>>14&16383)}}offset=paddedEnd}if(offset!==bytes.length||!image)return null;if(extended&&(extended.width!==image.width||extended.height!==image.height))return null;return extended??image}function text4(bytes,offset){return String.fromCharCode(...bytes.slice(offset,offset+4))}function u24(bytes,offset){return bytes[offset]|bytes[offset+1]<<8|bytes[offset+2]<<16}function u32(bytes,offset){return(bytes[offset]|bytes[offset+1]<<8|bytes[offset+2]<<16|bytes[offset+3]<<24)>>>0}var AGENT_MEDIA_MAX_BASE64_LENGTH=4*Math.ceil(MEDIA_RELAY_SAFE_MAX_BYTES/3);class AgentMediaError extends Error{code;constructor(code){super(code);this.code=code}}function fail(code){throw new AgentMediaError(code)}function validAgentMediaInput(value){if(!value||typeof value!=="object"||Array.isArray(value))return false;const media=value;return Object.keys(media).length===4&&Object.keys(media).every((key)=>["contentType","base64","byteSize","sha256"].includes(key))&&["image/webp","video/webm"].includes(media.contentType)&&typeof media.base64==="string"&&media.base64.length>0&&media.base64.length<=AGENT_MEDIA_MAX_BASE64_LENGTH&&media.base64.length%4===0&&/^[A-Za-z0-9+/]*={0,2}$/.test(media.base64)&&Number.isSafeInteger(media.byteSize)&&media.byteSize>0&&media.byteSize<=MEDIA_RELAY_SAFE_MAX_BYTES&&typeof media.sha256==="string"&&/^[0-9a-f]{64}$/.test(media.sha256)}async function inspectAgentMedia(value){if(!validAgentMediaInput(value))fail("invalid_media_input");const binary=atob(value.base64);if(btoa(binary)!==value.base64)fail("invalid_media_base64");const bytes=Uint8Array.from(binary,(character)=>character.charCodeAt(0));if(bytes.length!==value.byteSize)fail("media_size_mismatch");const hash=new Uint8Array(await crypto.subtle.digest("SHA-256",bytes.buffer));const sha256=Array.from(hash,(byte)=>byte.toString(16).padStart(2,"0")).join("");if(sha256!==value.sha256)fail("media_hash_mismatch");const dimensions=value.contentType==="image/webp"?await inspectImage(bytes):await inspectVideo(bytes);return{media:value.contentType==="image/webp"?{kind:"image",contentType:"image/webp",bytes}:{kind:"video",contentType:"video/webm",bytes},summary:{contentType:value.contentType,byteSize:bytes.length,sha256,...dimensions}}}async function inspectImage(bytes){const dimensions=readWebpDimensions(bytes);if(!dimensions)fail("invalid_media_container");if(dimensions.width<1||dimensions.height<1||dimensions.width>1024||dimensions.height>1024)fail("media_dimensions_too_large");try{const{default:decode}=await import("@jsquash/webp/decode.js");const decoded=await decode(Uint8Array.from(bytes).buffer);if(decoded.width!==dimensions.width||decoded.height!==dimensions.height)fail("invalid_media_container");return dimensions}catch{return fail("invalid_media_container")}}async function inspectVideo(bytes){const{Input,BufferSource,WEBM}=await import("mediabunny");const input=new Input({source:new BufferSource(bytes),formats:[WEBM]});let timeout;try{return await Promise.race([(async()=>{const[videos,audios,tracks]=await Promise.all([input.getVideoTracks(),input.getAudioTracks(),input.getTracks()]);if(videos.length!==1||audios.length>1||tracks.length!==videos.length+audios.length)fail("media_tracks_unsupported");const track=videos[0];const[codec,width,height,displayWidth,displayHeight,duration,stats]=await Promise.all([track.getCodec(),track.getCodedWidth(),track.getCodedHeight(),track.getDisplayWidth(),track.getDisplayHeight(),input.computeDuration(),track.computePacketStats(1)]);if(codec!=="vp8"&&codec!=="vp9")fail("media_codec_unsupported");if([width,height,displayWidth,displayHeight].some((size)=>!Number.isFinite(size)||size<1||size>512))fail("media_dimensions_too_large");if(!Number.isFinite(duration)||duration<=0||duration>30)fail("media_video_duration_invalid");if(stats.packetCount<1)fail("invalid_media_container");if(audios[0]&&!["opus","vorbis"].includes(await audios[0].getCodec()??""))fail("media_codec_unsupported");return{width,height,durationMs:Math.ceil(duration*1000)}})(),new Promise((_,reject)=>{timeout=setTimeout(()=>{input.dispose();reject(new AgentMediaError("media_inspection_timeout"))},5000)})])}catch(error){if(error instanceof AgentMediaError)throw error;return fail("invalid_media_container")}finally{clearTimeout(timeout);input.dispose()}}var MAPAPP_CATEGORY_TOKENS=["\uD83C\uDF31","\uD83D\uDCCD","\uD83E\uDDED","\uD83C\uDFA8","\uD83C\uDFB5","\uD83C\uDF7D\uFE0F","\u2615","\uD83D\uDED2","\uD83C\uDFC0","\uD83C\uDFAE","\uD83D\uDCF0","\uD83D\uDCAC","\uD83D\uDCF8","\uD83C\uDFAC","\uD83D\uDCBB","\uD83D\uDEE0\uFE0F","\uD83C\uDFE0","\uD83D\uDE97","\uD83C\uDF0A","\u26F0\uFE0F","\uD83C\uDF33","\uD83D\uDC3E","\uD83C\uDF93","\uD83C\uDFE5","\u26A0\uFE0F","\uD83C\uDF89","\uD83D\uDCBC","\uD83D\uDD2C","\u2708\uFE0F","\uD83E\uDDD8","\uD83E\uDE99","\u2764\uFE0F"];var DEFAULT_MAPAPP_CATEGORY=MAPAPP_CATEGORY_TOKENS[0];import{sendAllBsv,sendBsv}from"@1sat/actions";import{P2PKH,Transaction,Utils}from"@bsv/sdk";var MAX_DIRECT_BSV_SEND_SATOSHIS=2099999999999998;function validateDirectBsvInput(input){const address=input.to.trim();let decoded;try{decoded=Utils.fromBase58Check(address)}catch{return{ok:false,code:"bsv_address_invalid",message:"Enter a valid mainnet BSV address."}}if(decoded.data.length!==20){return{ok:false,code:"bsv_address_invalid",message:"Enter a valid mainnet P2PKH address."}}if(decoded.prefix.length!==1||decoded.prefix[0]!==0){return{ok:false,code:"bsv_address_wrong_network",message:"Direct sends require a mainnet BSV address."}}if(!("satoshis"in input))return{ok:true,address,max:true};if(!Number.isSafeInteger(input.satoshis)||input.satoshis<1||input.satoshis>MAX_DIRECT_BSV_SEND_SATOSHIS){return{ok:false,code:"bsv_amount_invalid",message:`Amount must be a whole number from 1 to ${MAX_DIRECT_BSV_SEND_SATOSHIS} satoshis.`}}return{ok:true,address,satoshis:input.satoshis}}function inspectDirectBsvEvidence(atomicBeef,address){try{const tx=Transaction.fromBEEF(atomicBeef);const script=new P2PKH().lock(address).toHex();const matching=tx.outputs.filter((output)=>output.lockingScript.toHex()===script);if(matching.length!==1)return null;const satoshis=matching[0]?.satoshis;if(typeof satoshis!=="number"||!Number.isSafeInteger(satoshis)||satoshis<1)return null;const inputSatoshis=tx.inputs.map((input)=>input.sourceTransaction?.outputs[input.sourceOutputIndex]?.satoshis);const fee=inputSatoshis.every((value)=>Number.isSafeInteger(value))?inputSatoshis.reduce((sum,value)=>sum+(value??0),0)-tx.outputs.reduce((sum,output)=>sum+(output.satoshis??0),0):null;return{satoshis,fee:fee!==null&&Number.isSafeInteger(fee)&&fee>=0?fee:null}}catch{return null}}import{Hash,Utils as Utils2}from"@bsv/sdk";var MESSAGING_IDENTITY_VERSION="mapapp-messaging-identity-v1";var MESSAGING_IDENTITY_MUTATION_VERSION="mapapp-messaging-identity-mutation-v1";var MAPAPP_MESSAGE_VERSION="mapapp-message-v1";var MAPAPP_MESSAGE_BOX_NAME="mapapp-messaging-v1";var MESSAGEBOX_PROTOCOL=[1,"messagebox"];var MESSAGEBOX_KEY_ID="1";var DEFAULT_MESSAGE_PLAINTEXT_MAX_BYTES=8*1024;var MAPAPP_MESSAGE_ID_MAX_BYTES=256;function serializeMessagingIdentityMutationV1(input){const mutation=assertMessagingIdentityMutationV1(input);return new TextEncoder().encode(JSON.stringify({version:mutation.version,operation:mutation.operation,bapId:mutation.bapId,walletIdentityKey:mutation.walletIdentityKey,messageBoxHost:mutation.messageBoxHost,deployment:mutation.deployment,canonicalOrigin:mutation.canonicalOrigin,network:mutation.network,expectedProfileOutpoint:mutation.expectedProfileOutpoint,expectedEvidenceHash:mutation.expectedEvidenceHash,acceptedSequence:mutation.acceptedSequence,projectionVersion:mutation.projectionVersion,clientOperationId:mutation.clientOperationId}))}function serializeMapAppMessageV1(input,maxPlaintextBytes=DEFAULT_MESSAGE_PLAINTEXT_MAX_BYTES){const message=assertMapAppMessageV1(input,maxPlaintextBytes);return JSON.stringify({version:message.version,messageId:message.messageId,senderIdentityKey:message.senderIdentityKey,recipientIdentityKey:message.recipientIdentityKey,conversationId:message.conversationId,sentAt:message.sentAt,text:message.text})}function conversationIdForIdentityKeys(first,second){assertCompressedIdentityKey(first,"first identity key");assertCompressedIdentityKey(second,"second identity key");if(first.toLowerCase()===second.toLowerCase())throw new TypeError("Self-messaging is not allowed.");const[left,right]=[first.toLowerCase(),second.toLowerCase()].sort();return Utils2.toHex(Hash.sha256(Array.from(new TextEncoder().encode(`mapapp-messaging/conversation/v1\\0${left}\\0${right}`))))}function assertMapAppMessageV1(value,maxPlaintextBytes=DEFAULT_MESSAGE_PLAINTEXT_MAX_BYTES){const record=strictRecord(value,["version","messageId","senderIdentityKey","recipientIdentityKey","conversationId","sentAt","text"],"MapAppMessageV1");if(record.version!==MAPAPP_MESSAGE_VERSION)throw new TypeError("Unsupported MapApp message version.");const messageId=stringField(record,"messageId");if(messageId.trim()===""||new TextEncoder().encode(messageId).byteLength>MAPAPP_MESSAGE_ID_MAX_BYTES)throw new TypeError("messageId must be a bounded non-empty string.");assertCanonicalIsoTimestamp(stringField(record,"sentAt"),"sentAt");const senderIdentityKey=stringField(record,"senderIdentityKey");const recipientIdentityKey=stringField(record,"recipientIdentityKey");assertCompressedIdentityKey(senderIdentityKey,"sender identity key");assertCompressedIdentityKey(recipientIdentityKey,"recipient identity key");if(senderIdentityKey.toLowerCase()===recipientIdentityKey.toLowerCase())throw new TypeError("Self-messaging is not allowed.");const expectedConversationId=conversationIdForIdentityKeys(senderIdentityKey,recipientIdentityKey);if(stringField(record,"conversationId")!==expectedConversationId)throw new TypeError("Message conversation ID does not match its participants.");if(!Number.isSafeInteger(maxPlaintextBytes)||maxPlaintextBytes<=0)throw new TypeError("Plaintext maximum must be a positive safe integer.");const text=stringField(record,"text");if(text.trim()==="")throw new TypeError("Message text must not be blank.");if(new TextEncoder().encode(text).byteLength>maxPlaintextBytes)throw new RangeError("Message text exceeds the plaintext maximum.");return record}function assertMessagingIdentityMutationV1(value){const record=strictRecord(value,["version","operation","bapId","walletIdentityKey","messageBoxHost","deployment","canonicalOrigin","network","expectedProfileOutpoint","expectedEvidenceHash","acceptedSequence","projectionVersion","clientOperationId"],"MessagingIdentityMutationV1");if(record.version!==MESSAGING_IDENTITY_MUTATION_VERSION)throw new TypeError("Unsupported messaging identity mutation version.");if(record.operation!=="register"&&record.operation!=="rotate"&&record.operation!=="revoke")throw new TypeError("Unsupported messaging identity operation.");for(const key of["bapId","messageBoxHost","deployment","canonicalOrigin","clientOperationId"])assertNonEmptyString(record[key],key);assertCompressedIdentityKey(stringField(record,"walletIdentityKey"),"wallet identity key");if(record.network!=="mainnet"&&record.network!=="testnet")throw new TypeError("Unsupported messaging network.");assertProfileEvidenceGroup(record);assertHttpsUrl(stringField(record,"messageBoxHost"),"messageBoxHost");assertHttpsUrl(stringField(record,"canonicalOrigin"),"canonicalOrigin");return record}function assertMessagingIdentityV1(value){const record=strictRecord(value,["version","bapId","walletIdentityKey","messageBoxHost","deployment","canonicalOrigin","network","expectedProfileOutpoint","expectedEvidenceHash","acceptedSequence","projectionVersion"],"MessagingIdentityV1");if(record.version!==MESSAGING_IDENTITY_VERSION)throw new TypeError("Unsupported messaging identity version.");for(const key of["bapId","messageBoxHost","deployment","canonicalOrigin"])assertNonEmptyString(record[key],key);assertCompressedIdentityKey(stringField(record,"walletIdentityKey"),"wallet identity key");if(record.network!=="mainnet"&&record.network!=="testnet")throw new TypeError("Unsupported messaging network.");assertProfileEvidenceGroup(record);assertHttpsUrl(stringField(record,"messageBoxHost"),"messageBoxHost");assertHttpsUrl(stringField(record,"canonicalOrigin"),"canonicalOrigin");return record}function assertCompressedIdentityKey(value,field="identity key"){if(!/^(02|03)[0-9a-fA-F]{64}$/.test(value))throw new TypeError(`${field} must be a compressed public key.`)}function strictRecord(value,keys,name){if(!value||typeof value!=="object"||Array.isArray(value))throw new TypeError(`${name} must be an object.`);const record=value;if(Object.keys(record).length!==keys.length||keys.some((key)=>!(key in record)))throw new TypeError(`${name} has unsupported or missing fields.`);return record}function stringField(record,key){const value=record[key];if(typeof value!=="string")throw new TypeError(`${key} must be a string.`);return value}function numberField(record,key){const value=record[key];if(typeof value!=="number"||!Number.isSafeInteger(value))throw new TypeError(`${key} must be a non-negative safe integer.`);return value}function assertProfileEvidenceGroup(record){const fields=[record.expectedProfileOutpoint,record.expectedEvidenceHash,record.acceptedSequence,record.projectionVersion];if(fields.every((value)=>value===null))return;if(fields.some((value)=>value===null))throw new TypeError("Profile evidence must be entirely present or absent.");assertNonEmptyString(record.expectedProfileOutpoint,"expectedProfileOutpoint");assertNonEmptyString(record.expectedEvidenceHash,"expectedEvidenceHash");if(numberField(record,"acceptedSequence")<1)throw new TypeError("acceptedSequence must be positive.");if(numberField(record,"projectionVersion")<0)throw new TypeError("projectionVersion must be non-negative.")}function assertNonEmptyString(value,field){if(typeof value!=="string"||value.trim()==="")throw new TypeError(`${field} must be a non-empty string.`)}function assertHttpsUrl(value,field){try{const parsed=new URL(String(value));if(parsed.protocol!=="https:"||parsed.username||parsed.password||parsed.pathname!=="/"||parsed.search||parsed.hash)throw new Error}catch{throw new TypeError(`${field} must be an HTTPS origin without a path.`)}}function assertCanonicalIsoTimestamp(value,field="timestamp"){if(!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(value)||!Number.isFinite(Date.parse(value))||new Date(value).toISOString()!==value)throw new TypeError(`${field} must be a canonical ISO-8601 UTC timestamp.`)}
|
|
3
|
-
export{POST_GEOHASH_MIN_PRECISION,POST_GEOHASH_MAX_PRECISION,POST_GEOHASH_DEFAULT_PRECISION,POST_GEOHASH_PATTERN,encodeGeohash,geohashBounds,MEDIA_RELAY_SAFE_MAX_BYTES,AGENT_MEDIA_MAX_BASE64_LENGTH,AgentMediaError,validAgentMediaInput,inspectAgentMedia,MAPAPP_CATEGORY_TOKENS,MAX_DIRECT_BSV_SEND_SATOSHIS,validateDirectBsvInput,inspectDirectBsvEvidence,MESSAGING_IDENTITY_MUTATION_VERSION,MAPAPP_MESSAGE_VERSION,MAPAPP_MESSAGE_BOX_NAME,MESSAGEBOX_PROTOCOL,MESSAGEBOX_KEY_ID,DEFAULT_MESSAGE_PLAINTEXT_MAX_BYTES,MAPAPP_MESSAGE_ID_MAX_BYTES,serializeMessagingIdentityMutationV1,serializeMapAppMessageV1,conversationIdForIdentityKeys,assertMapAppMessageV1,assertMessagingIdentityV1,assertCompressedIdentityKey,assertCanonicalIsoTimestamp};
|