@jdr377/mapapp-agent-connector 0.1.0-pre.13 → 0.1.0-pre.15
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 +8 -8
- package/dist/{chunk-ffcv7x5a.js → chunk-466n50gb.js} +1 -1
- package/dist/{chunk-7txe8897.js → chunk-a2rdf4kd.js} +6 -6
- package/dist/chunk-fp3attdv.js +3 -0
- package/dist/{chunk-kq6zsttw.js → chunk-mb8a3fs5.js} +1 -1
- package/dist/{chunk-d722pj7f.js → chunk-t3cx6wmg.js} +1 -1
- package/dist/chunk-t7bheq4v.js +3 -0
- package/dist/chunk-y7vmpgeg.js +17 -0
- package/dist/participant-mcp-server.js +5 -5
- package/distribution.json +23 -23
- package/package.json +1 -1
- package/dist/chunk-618mghb5.js +0 -17
- package/dist/chunk-jr7dhw6k.js +0 -3
- package/dist/chunk-rk0z9bdp.js +0 -3
package/dist/chunk-jr7dhw6k.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import*as z from"zod/v4";var diagnosticSchema=z.object({code:z.string(),remedy:z.string()}).describe("Allow-listed failure code and fixed remedy. Contains no upstream error text, credentials, private paths or message content.");var remedies=new Map;function group(remedy,codes){for(const code of codes)remedies.set(code,remedy)}group("Supply text, a valid post geohash, an exact category token and optional freshnessDuration/media. MapApp resolves lock amounts and heights; do not supply them.",["invalid_text_post_input"]);group("Check MapApp service readiness and current freshness policy, then retry preparation with the same ID. Do not guess lock amounts or heights.",["publication_policy_unavailable","prerequisite_unavailable","prerequisite_blocked"]);group("Read the original operation's status/reconcile tools. Review current policy before replacing an unexecuted preparation; never replace an attempted transaction.",["publication_policy_changed"]);group("Check the selected tool schema, command options and retained connection metadata. Preserve the original wallet binding.",["participant_configuration_invalid","participant_configuration_too_large","participant_invocation_invalid","participant_tool_not_found","participant_arguments_invalid","participant_arguments_too_large","participant_services_configuration_invalid","participant_wallet_target_invalid","payment_input_invalid","invalid_agent_wallet_connection_configuration","setup_deployment_invalid","setup_state_invalid","invalid_operation_id"]);group("Check retained state and input file paths. Reuse the original wallet or its recovery material; do not replace its root.",["participant_existing_wallet_required","participant_arguments_unavailable","setup_existing_directory_unrecognized","setup_file_invalid","setup_recovery_archive_invalid","restore_operations_invalid","local_intent_database_incompatible"]);group("Wait for the active connection or original operation to settle, then reopen the same state. Do not force an unlock or start a replacement action.",["local_intent_repository_busy","execution_in_progress","participant_closing","read_in_progress"]);group("Verify private-file access, writable storage and free space. Keep original files and keys; do not broaden access or recreate the wallet.",["local_intent_repository_open_failed","local_intent_durability_unavailable","local_intent_namespace_limit","wallet_backup_unavailable"]);group("Check the selected provider, unlock state and app permissions. Keep its expected identity and network; do not substitute a wallet.",["permission_denied","read_failed","read_timeout","required_method_missing","invalid_read_response","setup_provider_locked","setup_provider_denied","setup_provider_unavailable","setup_provider_binding_changed","participant_connection_changed","participant_wallet_identity_changed","participant_wallet_network_changed","provider_binding_changed","network_binding_changed","identity_binding_changed","caller_mismatch","setup_deployment_changed","setup_identity_changed","setup_wallet_binding_changed"]);group("Connect or unlock the selected wallet. Answer its authentication prompt, then retry the same command. Do not select another wallet.",["wallet_unauthenticated","setup_provider_unauthenticated"]);group("Check the deployment origin and the selected wallet's application-origin policy. Use the HTTPS deployment origin. Keep wallet permissions enabled.",["origin_refused","setup_provider_origin_refused"]);group("The selected wallet does not provide the requested authentication method. Use its supported connection procedure, then retry connect.",["setup_provider_authentication_unavailable"]);group("Use a new nonexistent destination for a new setup/restore. For recovery, retain the exact root, matching ZIP/binding and a closed checkpointed operation copy.",["restore_requires_new_directory","restore_operations_not_checkpointed","restore_outcome_unknown"]);group("Use the original operationId with this workflow's status/reconcile tools. Preserve original evidence; do not create a replacement spend or message.",["original_intake_unavailable","original_identity_unavailable","original_identity_interrupted","original_sponsor_evidence_unavailable","original_sponsor_or_intake_unavailable","original_sponsor_operation_interrupted","original_operation_interrupted","original_payment_evidence_unavailable","payment_evidence_mismatch","payment_binding_changed","wallet_commit_unverified","wallet_evidence_conflict","recovery_binding_conflict","exact_evidence_invalid","exact_evidence_unavailable","operation_already_started","original_identity_attempt_unresolved","operation_not_prepared","participant_operation_unavailable","setup_operation_unavailable","messaging_operation_unavailable","participant_invocation_unavailable","request_cancelled"]);group("The original operation is prepared. Execute that same ID only within user authority; do not create a replacement.",["operation_not_started"]);group("Wait for canonical ordering of the earlier grow/follow on this same target. If blockingOperation is returned, use its original operationId and workflow. Other targets and posts can proceed.",["social_confirmation_pending"]);group("The requested grow/follow state already exists. No transaction was created for this request.",["social_state_already_current"]);group("Inspect mapapp_locks and select its exact compatible output IDs. Keep the original wallet, metadata and operation; do not guess keys or replace outputs.",["lock_selection_invalid","lock_selection_changed","lock_operation_unavailable"]);group("Wait until the current chain height has passed the lock height, then inspect again. No reclaim transaction was created.",["locks_not_matured"]);group("Use mapapp_unlock_status/reconcile with the original operationId. Retain its evidence and wallet; never create a replacement reclaim.",["original_lock_evidence_unavailable","lock_evidence_mismatch"]);group("Report rejection only after the wallet explicitly refused without creating a transaction. A timeout, expiry or missing evidence is not a rejection. Preserve uncertain attempts for status/reconcile.",["wallet_rejection_report_required"]);group("Keep the original attempt and use status/reconcile. Known transaction IDs, evidence and conflicting intake states cannot be closed by a wallet rejection report.",["wallet_rejection_conflicts_with_evidence"]);group("Reuse the existing published identity and check readiness. Do not publish another identity.",["identity_already_published"]);group("Check retained wallet configuration and prerequisite availability. Keep original state; after an uncertain action, use its original operationId with status/reconcile.",["participant_startup_unavailable","participant_setup_unavailable","participant_close_unavailable","participant_prerequisite_unavailable","participant_prerequisite_invalid","identity_sponsor_unavailable","identity_prerequisite_changed","payment_services_unavailable"]);function participantDiagnostic(reason,fallback="participant_operation_unavailable"){const safeFallback=remedies.has(fallback)?fallback:"participant_operation_unavailable";const code=typeof reason==="string"&&remedies.has(reason)?reason:safeFallback;return{code,remedy:remedies.get(code)??remedies.get("participant_operation_unavailable")}}function participantErrorDiagnostic(error,fallback){const value=error&&typeof error==="object"?error:{};const filesystem={ENOENT:"participant_existing_wallet_required",EEXIST:"setup_existing_directory_unrecognized",EACCES:"local_intent_repository_open_failed",EPERM:"local_intent_repository_open_failed",ENOSPC:"local_intent_repository_open_failed"};const code=typeof value.code==="string"&&remedies.has(value.code)?value.code:typeof value.message==="string"&&remedies.has(value.message)?value.message:typeof value.code==="string"&&Object.hasOwn(filesystem,value.code)?filesystem[value.code]:value.name==="SyntaxError"||value.name==="ZodError"?"participant_configuration_invalid":undefined;return participantDiagnostic(code,fallback)}function outcomeDiagnostic(outcome){return outcome.kind==="blocked"||outcome.kind==="recovery_required"?{diagnostic:participantDiagnostic(outcome.reason)}:{}}function silenceParticipantConsole(){const methods=["log","info","warn","error","debug"];const originals=methods.map((method)=>console[method]);for(const method of methods)console[method]=()=>{};return()=>{methods.forEach((method,index)=>{console[method]=originals[index]})}}
|
|
3
|
-
export{diagnosticSchema,participantErrorDiagnostic,outcomeDiagnostic,silenceParticipantConsole};
|
package/dist/chunk-rk0z9bdp.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{createParticipantHTTPWallet,exportWalletDataZip,inspectWalletDataZip,openAgentLocalIntentRepository,parseParticipantConnection,participantMetadataSchema,readParticipantConnection,restoreWalletDataZip}from"./chunk-618mghb5.js";import{createAgentWalletConnectionInspector}from"./chunk-kq6zsttw.js";import"./chunk-e6y2yzbj.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 connection=options.restore?parseParticipantConnection(JSON.parse((await boundedFile(options.restore.connectionFile,4096)).toString())):{connectionId:`participant-${crypto.randomUUID()}`,callerId:`owner-${crypto.randomUUID()}`,originator:new URL(deployment).hostname};const meta2={connection,chain:"main",identityKey:key.toPublicKey().toString(),storageIdentityKey:crypto.randomUUID(),servicesBaseUrl:`${deployment}/api/bitcoin/wallet-services`};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
|
-
`);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");await readParticipantConnection(directory);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,persistenceAccess:"host_verification_required",identityPublication:published?"wallet_observed":"not_published",publicIdentityObservation:"not_checked",recovery:{rootFile:"root.wif",walletDataZip:recoveryArchive,operationStore:"agent-intents.sqlite",connectionFile:meta.connection?"wallet.json":"participant-authority.json"},delegation:"user_and_agent",next:published?"check_readiness":"prepare_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 connection={connectionId:`participant-${crypto.randomUUID()}`,callerId:`owner-${crypto.randomUUID()}`,originator};const wallet=createParticipantHTTPWallet(options.walletEndpoint,originator,deployment);const inspector=createAgentWalletConnectionInspector({wallet,binding:{connectionId:connection.connectionId,callerId:connection.callerId,originator,expectedIdentityKey:options.identityKey,expectedNetwork:"mainnet",route:"existing_brc100",declaredAuthority:"provider"}});let observed=await inspector.inspect(connection.callerId);if(observed.state==="unauthenticated"||observed.state==="locked"){try{if((await wallet.waitForAuthentication({})).authenticated!==true)throw new ParticipantSetupError("setup_provider_unauthenticated")}catch(error){if(error instanceof ParticipantSetupError)throw error;const code=error&&typeof error==="object"&&"code"in error?error.code:undefined;throw new ParticipantSetupError(code==="ERR_PERMISSION_DENIED"?"setup_provider_denied":code==="ERR_WALLET_LOCKED"?"setup_provider_locked":code==="ERR_WALLET_ORIGIN_REFUSED"?"setup_provider_origin_refused":code==="ERR_METHOD_NOT_SUPPORTED"?"setup_provider_authentication_unavailable":code==="ERR_WALLET_UNAUTHENTICATED"?"setup_provider_unauthenticated":"setup_provider_unavailable")}observed=await inspector.inspect(connection.callerId)}if(observed.reason==="origin_refused")throw new ParticipantSetupError("setup_provider_origin_refused");if(observed.state!=="ready")throw new ParticipantSetupError(`setup_provider_${observed.state}`);await mkdir(directory,{mode:448});await protectedWrite(join(directory,"wallet.json"),JSON.stringify({connection,transport:"brc100_http",chain:"main",identityKey:options.identityKey,servicesBaseUrl:`${deployment}/api/bitcoin/wallet-services`,walletEndpoint:options.walletEndpoint}));const owned=openAgentLocalIntentRepository(join(directory,"agent-intents.sqlite"));owned.close();return{schema,state:"provider_bound",route:"existing_brc100",identityKey:options.identityKey,network:"mainnet",persistenceAccess:"host_verification_required",delegation:"user_and_agent",backup:"provider_owned",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};
|