@1sat/actions 0.0.126 → 0.0.128
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.
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
* Cosign Token Deliveries Sync Action
|
|
3
3
|
*
|
|
4
4
|
* One-shot pull from a MessageBox slot used by cosign-wrapped BSV21 mints
|
|
5
|
-
* and transfers. Each message body carries a finalized BEEF,
|
|
6
|
-
* customInstructions the recipient will need
|
|
5
|
+
* and transfers. Each (decrypted) message body carries a finalized BEEF,
|
|
6
|
+
* the cosign customInstructions the recipient will need at spend time, and
|
|
7
7
|
* the output index that's owned by this wallet. We internalize the output
|
|
8
|
-
* into the bsv21 basket with the supplied customInstructions verbatim
|
|
9
|
-
* (no derivation re-write — these are cosign-protocol keys, not BRC-29).
|
|
8
|
+
* into the bsv21 basket with the supplied customInstructions verbatim.
|
|
10
9
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* Uses `@bsv/p2p` MessageBoxClient so encrypted bodies are decrypted using
|
|
11
|
+
* BRC-2 ECDH/AES-256-GCM via the wallet (matches what the sender used to
|
|
12
|
+
* encrypt). Intended call sites: any UI mount where a fresh sync is
|
|
13
|
+
* desired (e.g. yours-wallet popup mount). Not a polling loop.
|
|
13
14
|
*/
|
|
14
15
|
import type { Action } from '../types';
|
|
15
16
|
export interface SyncCosignDeliveriesInput {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syncCosignDeliveries.d.ts","sourceRoot":"","sources":["../../src/sync/syncCosignDeliveries.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"syncCosignDeliveries.d.ts","sourceRoot":"","sources":["../../src/sync/syncCosignDeliveries.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAMtC,MAAM,WAAW,yBAAyB;IACzC,uDAAuD;IACvD,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,0BAA0B;IAC1C,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAA;IACjB,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAA;CACd;AAiBD,eAAO,MAAM,oBAAoB,EAAE,MAAM,CACxC,yBAAyB,EACzB,0BAA0B,CAqH1B,CAAA"}
|
|
@@ -2,17 +2,18 @@
|
|
|
2
2
|
* Cosign Token Deliveries Sync Action
|
|
3
3
|
*
|
|
4
4
|
* One-shot pull from a MessageBox slot used by cosign-wrapped BSV21 mints
|
|
5
|
-
* and transfers. Each message body carries a finalized BEEF,
|
|
6
|
-
* customInstructions the recipient will need
|
|
5
|
+
* and transfers. Each (decrypted) message body carries a finalized BEEF,
|
|
6
|
+
* the cosign customInstructions the recipient will need at spend time, and
|
|
7
7
|
* the output index that's owned by this wallet. We internalize the output
|
|
8
|
-
* into the bsv21 basket with the supplied customInstructions verbatim
|
|
9
|
-
* (no derivation re-write — these are cosign-protocol keys, not BRC-29).
|
|
8
|
+
* into the bsv21 basket with the supplied customInstructions verbatim.
|
|
10
9
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* Uses `@bsv/p2p` MessageBoxClient so encrypted bodies are decrypted using
|
|
11
|
+
* BRC-2 ECDH/AES-256-GCM via the wallet (matches what the sender used to
|
|
12
|
+
* encrypt). Intended call sites: any UI mount where a fresh sync is
|
|
13
|
+
* desired (e.g. yours-wallet popup mount). Not a polling loop.
|
|
13
14
|
*/
|
|
15
|
+
import { MessageBoxClient } from '@bsv/p2p';
|
|
14
16
|
import { Utils } from '@bsv/sdk';
|
|
15
|
-
import { AuthFetch } from '@bsv/sdk/auth';
|
|
16
17
|
// ============================================================================
|
|
17
18
|
// Action
|
|
18
19
|
// ============================================================================
|
|
@@ -38,52 +39,59 @@ export const syncCosignDeliveries = {
|
|
|
38
39
|
},
|
|
39
40
|
async execute(ctx, input) {
|
|
40
41
|
const messageBox = input.messageBox || 'cosign_token_inbox';
|
|
41
|
-
const
|
|
42
|
+
const host = input.messageboxUrl?.replace(/\/+$/, '') ||
|
|
42
43
|
'https://messagebox.1sat.app';
|
|
43
|
-
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (!listResponse.ok) {
|
|
51
|
-
throw new Error(`Failed to list messages: ${listResponse.status} ${listResponse.statusText}`);
|
|
52
|
-
}
|
|
53
|
-
const { messages } = (await listResponse.json());
|
|
54
|
-
if (!messages || messages.length === 0) {
|
|
44
|
+
// MessageBoxClient encrypts on send and decrypts on listMessages,
|
|
45
|
+
// so we go through it (not raw AuthFetch) — the bodies on the wire
|
|
46
|
+
// are AES-256-GCM ciphertext under BRC-2 ECDH keys.
|
|
47
|
+
// biome-ignore lint/suspicious/noExplicitAny: WalletInterface typing diff between @bsv/sdk versions
|
|
48
|
+
const client = new MessageBoxClient({ walletClient: ctx.wallet, host });
|
|
49
|
+
const messages = await client.listMessages({ messageBox, host });
|
|
50
|
+
if (messages.length === 0) {
|
|
55
51
|
return { processed: 0, failed: 0 };
|
|
56
52
|
}
|
|
57
|
-
// 2. Internalize each delivery into the wallet's bsv21 basket.
|
|
58
53
|
let processed = 0;
|
|
59
54
|
let failed = 0;
|
|
60
55
|
const acknowledgedIds = [];
|
|
61
56
|
for (const msg of messages) {
|
|
62
57
|
try {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
58
|
+
// MessageBoxClient.listMessages returns body as already-parsed
|
|
59
|
+
// JSON object when the cleartext was JSON. Defensive: parse if
|
|
60
|
+
// we still see a string.
|
|
61
|
+
const body = typeof msg.body === 'string'
|
|
62
|
+
? JSON.parse(msg.body)
|
|
63
|
+
: msg.body;
|
|
64
|
+
console.log(`[syncCosignDeliveries] message ${msg.messageId} parsed body keys:`, Object.keys(body));
|
|
65
|
+
if (!body.tokenId ||
|
|
66
|
+
body.vout === undefined ||
|
|
67
|
+
!body.beef ||
|
|
68
|
+
!body.customInstructions) {
|
|
69
|
+
throw new Error(`message body missing required fields (have keys: ${Object.keys(body).join(',')})`);
|
|
70
|
+
}
|
|
71
|
+
const beefBytes = Array.isArray(body.beef)
|
|
72
|
+
? body.beef
|
|
73
|
+
: Utils.toArray(body.beef, 'hex');
|
|
74
|
+
const tokenIdShort = String(body.tokenId).slice(0, 8);
|
|
67
75
|
const tags = [
|
|
68
|
-
`bsv21:${
|
|
69
|
-
`amt:${
|
|
70
|
-
`tokenId:${
|
|
76
|
+
`bsv21:${body.tokenId}`,
|
|
77
|
+
`amt:${body.amount ?? '0'}`,
|
|
78
|
+
`tokenId:${body.tokenId}`,
|
|
71
79
|
];
|
|
72
80
|
await ctx.wallet.internalizeAction({
|
|
73
81
|
tx: beefBytes,
|
|
74
82
|
outputs: [
|
|
75
83
|
{
|
|
76
|
-
outputIndex:
|
|
84
|
+
outputIndex: body.vout,
|
|
77
85
|
protocol: 'basket insertion',
|
|
78
86
|
insertionRemittance: {
|
|
79
87
|
basket: 'bsv21',
|
|
80
88
|
tags,
|
|
81
|
-
customInstructions:
|
|
89
|
+
customInstructions: body.customInstructions,
|
|
82
90
|
},
|
|
83
91
|
},
|
|
84
92
|
],
|
|
85
|
-
description: `Cosign token delivery (${
|
|
86
|
-
labels: [`bsv21:${
|
|
93
|
+
description: `Cosign token delivery (${tokenIdShort}…)`.slice(0, 50),
|
|
94
|
+
labels: [`bsv21:${body.tokenId}`],
|
|
87
95
|
});
|
|
88
96
|
acknowledgedIds.push(msg.messageId);
|
|
89
97
|
processed++;
|
|
@@ -93,15 +101,12 @@ export const syncCosignDeliveries = {
|
|
|
93
101
|
failed++;
|
|
94
102
|
}
|
|
95
103
|
}
|
|
96
|
-
// 3. Acknowledge successfully internalized messages.
|
|
97
104
|
if (acknowledgedIds.length > 0) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (!ackResponse.ok) {
|
|
104
|
-
console.error(`[syncCosignDeliveries] Failed to acknowledge messages: ${ackResponse.status}`);
|
|
105
|
+
try {
|
|
106
|
+
await client.acknowledgeMessage({ messageIds: acknowledgedIds, host });
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
console.error('[syncCosignDeliveries] Failed to acknowledge messages:', err instanceof Error ? err.message : String(err));
|
|
105
110
|
}
|
|
106
111
|
}
|
|
107
112
|
return { processed, failed };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syncCosignDeliveries.js","sourceRoot":"","sources":["../../src/sync/syncCosignDeliveries.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"syncCosignDeliveries.js","sourceRoot":"","sources":["../../src/sync/syncCosignDeliveries.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAgChC,+EAA+E;AAC/E,SAAS;AACT,+EAA+E;AAE/E,MAAM,CAAC,MAAM,oBAAoB,GAG7B;IACH,IAAI,EAAE;QACL,IAAI,EAAE,sBAAsB;QAC5B,WAAW,EACV,6FAA6F;QAC9F,QAAQ,EAAE,MAAM;QAChB,WAAW,EAAE;YACZ,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACX,UAAU,EAAE;oBACX,IAAI,EAAE,QAAQ;oBACd,WAAW,EACV,+DAA+D;iBAChE;gBACD,aAAa,EAAE;oBACd,IAAI,EAAE,QAAQ;oBACd,WAAW,EACV,gEAAgE;iBACjE;aACD;SACD;QACD,gBAAgB,EAAE,KAAK;KACvB;IAED,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK;QACvB,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,IAAI,oBAAoB,CAAA;QAC3D,M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CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACtD,CAAA;gBACD,MAAM,EAAE,CAAA;YACT,CAAC;QACF,CAAC;QAED,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,IAAI,CAAC;gBACJ,MAAM,MAAM,CAAC,kBAAkB,CAAC,EAAE,UAAU,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,CAAA;YACvE,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACd,OAAO,CAAC,KAAK,CACZ,wDAAwD,EACxD,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAChD,CAAA;YACF,CAAC;QACF,CAAC;QAED,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,CAAA;IAC7B,CAAC;CACD,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1sat/actions",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.128",
|
|
4
4
|
"description": "Action definitions for the 1Sat SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"@1sat/types": "0.0.20",
|
|
34
34
|
"@1sat/utils": "0.0.16",
|
|
35
35
|
"@1sat/wallet": "0.0.68",
|
|
36
|
-
"@1sat/templates": "0.0.12"
|
|
36
|
+
"@1sat/templates": "0.0.12",
|
|
37
|
+
"@bsv/p2p": "^1.1.6"
|
|
37
38
|
},
|
|
38
39
|
"peerDependencies": {
|
|
39
40
|
"@bsv/sdk": "^2.0.13"
|