@1sat/actions 0.0.235 → 0.1.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.
Files changed (96) hide show
  1. package/dist/1color/deploy.d.ts +35 -0
  2. package/dist/1color/deploy.d.ts.map +1 -0
  3. package/dist/1color/deploy.js +127 -0
  4. package/dist/1color/deploy.js.map +1 -0
  5. package/dist/{mandala → 1color}/deploy.test.d.ts.map +1 -1
  6. package/dist/1color/deploy.test.js +188 -0
  7. package/dist/1color/deploy.test.js.map +1 -0
  8. package/dist/1color/index.d.ts +10 -0
  9. package/dist/{mandala → 1color}/index.d.ts.map +1 -1
  10. package/dist/1color/index.js +12 -0
  11. package/dist/1color/index.js.map +1 -0
  12. package/dist/1color/receipt.d.ts +39 -0
  13. package/dist/1color/receipt.d.ts.map +1 -0
  14. package/dist/1color/receipt.js +91 -0
  15. package/dist/1color/receipt.js.map +1 -0
  16. package/dist/1color/send.d.ts +52 -0
  17. package/dist/1color/send.d.ts.map +1 -0
  18. package/dist/1color/send.js +175 -0
  19. package/dist/1color/send.js.map +1 -0
  20. package/dist/{mandala → 1color}/send.test.d.ts.map +1 -1
  21. package/dist/1color/send.test.js +622 -0
  22. package/dist/1color/send.test.js.map +1 -0
  23. package/dist/funding/walletFunding.d.ts +1 -2
  24. package/dist/funding/walletFunding.d.ts.map +1 -1
  25. package/dist/funding/walletFunding.js +1 -2
  26. package/dist/funding/walletFunding.js.map +1 -1
  27. package/dist/index.d.ts +1 -1
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +3 -3
  30. package/dist/index.js.map +1 -1
  31. package/dist/listings/cancelOwnedListings.d.ts.map +1 -1
  32. package/dist/listings/cancelOwnedListings.js +7 -3
  33. package/dist/listings/cancelOwnedListings.js.map +1 -1
  34. package/dist/locks/index.d.ts.map +1 -1
  35. package/dist/locks/index.js +2 -1
  36. package/dist/locks/index.js.map +1 -1
  37. package/dist/metanet/delivery.d.ts +69 -0
  38. package/dist/metanet/delivery.d.ts.map +1 -0
  39. package/dist/metanet/delivery.js +235 -0
  40. package/dist/metanet/delivery.js.map +1 -0
  41. package/dist/metanet/delivery.test.d.ts +2 -0
  42. package/dist/metanet/delivery.test.d.ts.map +1 -0
  43. package/dist/metanet/delivery.test.js +125 -0
  44. package/dist/metanet/delivery.test.js.map +1 -0
  45. package/dist/metanet/envelope.test.js +1 -1
  46. package/dist/metanet/envelope.test.js.map +1 -1
  47. package/dist/metanet/inbox.d.ts +2 -2
  48. package/dist/metanet/inbox.js +2 -2
  49. package/dist/metanet/index.d.ts +5 -3
  50. package/dist/metanet/index.d.ts.map +1 -1
  51. package/dist/metanet/index.js +6 -4
  52. package/dist/metanet/index.js.map +1 -1
  53. package/dist/metanet/receive.d.ts +46 -16
  54. package/dist/metanet/receive.d.ts.map +1 -1
  55. package/dist/metanet/receive.js +118 -17
  56. package/dist/metanet/receive.js.map +1 -1
  57. package/dist/metanet/relay.d.ts +1 -1
  58. package/dist/metanet/relay.js +1 -1
  59. package/dist/metanet/testdata/brc232-vectors.json +86 -0
  60. package/dist/opns/index.d.ts.map +1 -1
  61. package/dist/opns/index.js +2 -1
  62. package/dist/opns/index.js.map +1 -1
  63. package/dist/ordinals/index.d.ts.map +1 -1
  64. package/dist/ordinals/index.js +2 -1
  65. package/dist/ordinals/index.js.map +1 -1
  66. package/dist/payments/index.d.ts +1 -1
  67. package/dist/payments/index.js +3 -3
  68. package/dist/payments/index.js.map +1 -1
  69. package/dist/payments/sendBsvHandle.test.js +52 -34
  70. package/dist/payments/sendBsvHandle.test.js.map +1 -1
  71. package/package.json +10 -9
  72. package/dist/mandala/deploy.d.ts +0 -89
  73. package/dist/mandala/deploy.d.ts.map +0 -1
  74. package/dist/mandala/deploy.js +0 -226
  75. package/dist/mandala/deploy.js.map +0 -1
  76. package/dist/mandala/deploy.test.js +0 -281
  77. package/dist/mandala/deploy.test.js.map +0 -1
  78. package/dist/mandala/index.d.ts +0 -9
  79. package/dist/mandala/index.js +0 -17
  80. package/dist/mandala/index.js.map +0 -1
  81. package/dist/mandala/receive.d.ts +0 -58
  82. package/dist/mandala/receive.d.ts.map +0 -1
  83. package/dist/mandala/receive.js +0 -162
  84. package/dist/mandala/receive.js.map +0 -1
  85. package/dist/mandala/send.d.ts +0 -74
  86. package/dist/mandala/send.d.ts.map +0 -1
  87. package/dist/mandala/send.js +0 -313
  88. package/dist/mandala/send.js.map +0 -1
  89. package/dist/mandala/send.test.js +0 -515
  90. package/dist/mandala/send.test.js.map +0 -1
  91. package/dist/mandala/tokenId.d.ts +0 -21
  92. package/dist/mandala/tokenId.d.ts.map +0 -1
  93. package/dist/mandala/tokenId.js +0 -29
  94. package/dist/mandala/tokenId.js.map +0 -1
  95. /package/dist/{mandala → 1color}/deploy.test.d.ts +0 -0
  96. /package/dist/{mandala → 1color}/send.test.d.ts +0 -0
@@ -1,162 +0,0 @@
1
- /**
2
- * Collect BRC-232 transaction deliveries from the wallet's `mandala_inbox`.
3
- *
4
- * For each message listed (BRC-231 over BRC-104): decode the BRC-169 §7.3
5
- * DAG-CBOR envelope, verify its §7.2 signature against `sender.identityKey`,
6
- * decrypt the BRC-78 `content` with `wallet.decrypt`, check `contentHash`,
7
- * parse the MIME entity, require `application/vnd.metanet.transaction+cbor`,
8
- * decode the DAG-CBOR body and internalize its outputs:
9
- *
10
- * - `wallet payment` → `paymentRemittance { derivationPrefix,
11
- * derivationSuffix, senderIdentityKey }`;
12
- * - `basket insertion` under a `mandala <txid> <vout>` protocol → basket
13
- * `mandala <txid> <vout>`, customInstructions = the derivation triple as given,
14
- * labels `mandala` and `mandala <txid> <vout>`, after checking that the output's
15
- * script names that token.
16
- *
17
- * A message is internalized whole or not at all, and acknowledged only after
18
- * its internalize succeeds. Anything else (an unknown content type or
19
- * protocolID, a token id mismatch, a bad signature, …) leaves the message
20
- * unacknowledged and is reported. SPV is `internalizeAction`'s.
21
- */
22
- import { Mandala } from '@1sat/templates';
23
- import { MANDALA_INBOX, MANDALA_LABEL, mandalaTokenBasket, mandalaTokenLabel, parseMandalaName, } from '@1sat/types';
24
- import { TRANSACTION_CBOR_CONTENT_TYPE, mediaType } from '@1sat/utils';
25
- import { Beef, } from '@bsv/sdk';
26
- import { decode as dagCborDecode } from '@ipld/dag-cbor';
27
- import { InboxSkipError as Skip, bytesHex, processInbox, } from '../metanet/inbox.js';
28
- import { mandalaTokenOf } from './tokenId.js';
29
- const MANDALA_PREFIX = 'mandala ';
30
- /** Build the internalize outputs and labels for one delivery, or throw Skip. */
31
- function planInternalize(body) {
32
- const txid = bytesHex(body.txid, 32, 'txid');
33
- if (!(body.beef instanceof Uint8Array))
34
- throw new Skip('beef must be bytes');
35
- if (!Array.isArray(body.outputs) || body.outputs.length === 0) {
36
- throw new Skip('outputs must be a non-empty array');
37
- }
38
- const beef = Beef.fromBinary(Array.from(body.beef));
39
- const subject = beef.findTxid(txid)?.tx;
40
- if (!subject)
41
- throw new Skip(`beef does not contain ${txid}`);
42
- const outputs = [];
43
- const tokenIds = [];
44
- const seen = new Set();
45
- for (const entry of body.outputs) {
46
- const outputIndex = entry.outputIndex;
47
- if (typeof outputIndex !== 'number' ||
48
- !subject.outputs[outputIndex] ||
49
- seen.has(outputIndex)) {
50
- throw new Skip(`bad outputIndex ${String(outputIndex)}`);
51
- }
52
- seen.add(outputIndex);
53
- if (entry.protocol === 'wallet payment') {
54
- if (typeof entry.derivationPrefix !== 'string' ||
55
- typeof entry.derivationSuffix !== 'string') {
56
- throw new Skip(`output ${outputIndex}: bad payment remittance`);
57
- }
58
- outputs.push({
59
- outputIndex,
60
- protocol: 'wallet payment',
61
- paymentRemittance: {
62
- derivationPrefix: entry.derivationPrefix,
63
- derivationSuffix: entry.derivationSuffix,
64
- senderIdentityKey: bytesHex(entry.senderIdentityKey, 33, 'senderIdentityKey'),
65
- },
66
- });
67
- continue;
68
- }
69
- if (entry.protocol !== 'basket insertion') {
70
- throw new Skip(`output ${outputIndex}: unknown protocol ${String(entry.protocol)}`);
71
- }
72
- const protocolID = entry.protocolID;
73
- const name = Array.isArray(protocolID) ? protocolID[1] : undefined;
74
- if (typeof name !== 'string' || !name.startsWith(MANDALA_PREFIX)) {
75
- throw new Skip(`output ${outputIndex}: unknown protocolID ${JSON.stringify(protocolID)}`);
76
- }
77
- if (typeof entry.keyID !== 'string') {
78
- throw new Skip(`output ${outputIndex}: keyID must be a string`);
79
- }
80
- const counterparty = bytesHex(entry.counterparty, 33, 'counterparty');
81
- // The protocol names the token by its deploy outpoint; the script's
82
- // BRC-162 id must name the same outpoint.
83
- const named = parseMandalaName(name);
84
- if (!named) {
85
- throw new Skip(`output ${outputIndex}: malformed Mandala protocol ${name}`);
86
- }
87
- const tokenId = `${named.txid}.${named.vout}`;
88
- const token = Mandala.decode(subject.outputs[outputIndex].lockingScript);
89
- const scriptTokenId = token
90
- ? mandalaTokenOf(token, txid, outputIndex)
91
- : undefined;
92
- if (scriptTokenId === undefined || scriptTokenId !== tokenId) {
93
- throw new Skip(`output ${outputIndex}: token mismatch (protocolID ${tokenId}, script ${scriptTokenId ?? 'none'})`);
94
- }
95
- outputs.push({
96
- outputIndex,
97
- protocol: 'basket insertion',
98
- insertionRemittance: {
99
- basket: mandalaTokenBasket(tokenId),
100
- customInstructions: JSON.stringify({
101
- protocolID,
102
- keyID: entry.keyID,
103
- counterparty,
104
- }),
105
- },
106
- });
107
- if (!tokenIds.includes(tokenId))
108
- tokenIds.push(tokenId);
109
- }
110
- const labels = tokenIds.length
111
- ? [MANDALA_LABEL, ...tokenIds.map(mandalaTokenLabel)]
112
- : [];
113
- return { txid, tx: beef.toBinaryAtomic(txid), outputs, labels, tokenIds };
114
- }
115
- /**
116
- * Internalize one BRC-232 delivery (the DAG-CBOR body of an
117
- * `application/vnd.metanet.transaction+cbor` MIME entity), whole or not at
118
- * all.
119
- *
120
- * @throws InboxSkipError when the body is malformed, names an unknown
121
- * protocol or protocolID, or a token protocolID does not match the script;
122
- * the internalize error when the wallet refuses it
123
- */
124
- export async function internalizeTransactionDelivery(wallet, body) {
125
- const plan = planInternalize(dagCborDecode(body));
126
- await wallet.internalizeAction({
127
- tx: plan.tx,
128
- outputs: plan.outputs,
129
- ...(plan.labels.length && { labels: plan.labels }),
130
- description: plan.tokenIds.length
131
- ? 'Receive Mandala tokens'
132
- : 'Receive delivered outputs',
133
- });
134
- return { txid: plan.txid, tokenIds: plan.tokenIds };
135
- }
136
- export const syncMandalaInbox = {
137
- meta: {
138
- name: 'syncMandalaInbox',
139
- description: 'Collect BRC-232 transaction deliveries (Mandala tokens, BRC-29 payments) from the mandala_inbox message box and internalize them',
140
- category: 'sync',
141
- inputSchema: {
142
- type: 'object',
143
- properties: {
144
- messageboxUrl: {
145
- type: 'string',
146
- description: 'MessageBox server URL (default: "https://messagebox.1sat.app")',
147
- },
148
- },
149
- },
150
- requiresServices: false,
151
- },
152
- async execute(ctx, input) {
153
- return processInbox(ctx.wallet, input.messageboxUrl, MANDALA_INBOX, async ({ entity }, msg) => {
154
- if (mediaType(entity.contentType) !== TRANSACTION_CBOR_CONTENT_TYPE) {
155
- throw new Skip(`unsupported content type ${entity.contentType}`);
156
- }
157
- const { txid, tokenIds } = await internalizeTransactionDelivery(ctx.wallet, entity.body);
158
- return { messageId: msg.messageId, txid, tokenIds };
159
- });
160
- },
161
- };
162
- //# sourceMappingURL=receive.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"receive.js","sourceRoot":"","sources":["../../src/mandala/receive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EACN,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,GAChB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,6BAA6B,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACtE,OAAO,EACN,IAAI,GAIJ,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,MAAM,IAAI,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AAE;YACZ,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACX,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,OAAO,YAAY,CAClB,GAAG,CAAC,MAAM,EACV,KAAK,CAAC,aAAa,EACnB,aAAa,EACb,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,EAAE;YACzB,IAAI,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,6BAA6B,EAAE,CAAC;gBACrE,MAAM,IAAI,IAAI,CAAC,4BAA4B,MAAM,CAAC,WAAW,EAAE,CAAC,CAAA;YACjE,CAAC;YACD,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,MAAM,8BAA8B,CAC9D,GAAG,CAAC,MAAM,EACV,MAAM,CAAC,IAAI,CACX,CAAA;YACD,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAA;QACpD,CAAC,CACD,CAAA;IACF,CAAC;CACD,CAAA"}
@@ -1,74 +0,0 @@
1
- /**
2
- * Mandala (BRC-162) send to a BRC-169 handle, delivered per BRC-232.
3
- *
4
- * 1. Resolve the handle (`resolveHandle`): identity key + messagebox.
5
- * 2. When no single token output in `mandala <txid> <vout>` holds exactly `amount`,
6
- * split first: an ordinary, broadcast action spending token outputs into
7
- * an exact-`amount` output and a remainder, both back to the wallet under
8
- * `mandalaProtocol(tokenId)` in the token's basket.
9
- * 3. The protected send: one `createAction` spending only the exact output,
10
- * with one output, the recipient's token output, locked to the key
11
- * derived under `mandalaProtocol(tokenId)` with keyID
12
- * `<derivationPrefix> <derivationSuffix>` (fresh random base64) and
13
- * counterparty = the recipient. `noSend`, labels `mandala`,
14
- * `mandala <txid> <vout>` and `p nosend expiry seconds <n>` (BRC-177; the wallet
15
- * funds it). It is not broadcast: the recipient broadcasts by
16
- * internalizing (BRC-169 §6.1, BRC-232 rule 4).
17
- * 4. Delivery: a signed BRC-169 §7.3 envelope (DAG-CBOR, BRC-231 body over
18
- * BRC-104) to the resolved messagebox, box `mandala_inbox`, `payment:
19
- * null`. `content` is BRC-78 encryption (via `wallet.encrypt`) of a MIME
20
- * entity of type `application/vnd.metanet.transaction+cbor` whose DAG-CBOR
21
- * body is the BRC-232 delivery `{ txid, beef, outputs: [ basket insertion
22
- * ] }`; `contentHash` is the SHA-256 of the MIME bytes.
23
- *
24
- * When delivery fails the result carries the error with `txid` and `tx`, so
25
- * the caller can retry delivery or `abortAction` the send.
26
- */
27
- import { type WalletProtocol } from '@bsv/sdk';
28
- import type { Action } from '../types.js';
29
- export interface SendMandalaInput {
30
- /** Token: the deploy outpoint, BRC-36 `<txid>.<vout>` (`<txid>_<vout>` accepted) */
31
- tokenId: string;
32
- /** Amount in raw units */
33
- amount: bigint | string;
34
- /** BRC-169 handle: `@handle@domain` or `handle@domain` */
35
- destination: {
36
- handle: string;
37
- };
38
- /**
39
- * BRC-177 `nosend expiry seconds` for the protected send (default
40
- * {@link METANET_SEND_EXPIRY_SECONDS}, one year).
41
- */
42
- expirySeconds?: number;
43
- /** Optional free text carried as the BRC-232 `memo` */
44
- memo?: string;
45
- }
46
- export interface SendMandalaResult {
47
- txid?: string;
48
- /** Atomic BEEF of the send */
49
- tx?: number[];
50
- /** `envelope`: BRC-169 envelope to the handle's messagebox, not broadcast */
51
- delivered?: 'envelope';
52
- /** Messagebox message id */
53
- messageId?: string;
54
- error?: string;
55
- }
56
- /** A BRC-232 `basket insertion` output entry. */
57
- export interface MandalaDeliveryOutput {
58
- outputIndex: number;
59
- protocol: 'basket insertion';
60
- protocolID: WalletProtocol;
61
- keyID: string;
62
- /** bstr(33): the key the recipient derives against (the sender's identity) */
63
- counterparty: Uint8Array;
64
- }
65
- /** The BRC-232 DAG-CBOR body a Mandala send delivers. */
66
- export interface MandalaDeliveryBody {
67
- memo?: string;
68
- /** bstr(32), display byte order (as in the BRC-95 Atomic BEEF header) */
69
- txid: Uint8Array;
70
- beef: Uint8Array;
71
- outputs: MandalaDeliveryOutput[];
72
- }
73
- export declare const sendMandala: Action<SendMandalaInput, SendMandalaResult>;
74
- //# sourceMappingURL=send.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"send.d.ts","sourceRoot":"","sources":["../../src/mandala/send.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAaH,OAAO,EAON,KAAK,cAAc,EACnB,MAAM,UAAU,CAAA;AAGjB,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,aAAa,CAAA;AASxD,MAAM,WAAW,gBAAgB;IAChC,oFAAoF;IACpF,OAAO,EAAE,MAAM,CAAA;IACf,0BAA0B;IAC1B,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,0DAA0D;IAC1D,WAAW,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;IAC/B;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,uDAAuD;IACvD,IAAI,CAAC,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,iBAAiB;IACjC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,8BAA8B;IAC9B,EAAE,CAAC,EAAE,MAAM,EAAE,CAAA;IACb,6EAA6E;IAC7E,SAAS,CAAC,EAAE,UAAU,CAAA;IACtB,4BAA4B;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;CACd;AAED,iDAAiD;AACjD,MAAM,WAAW,qBAAqB;IACrC,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,kBAAkB,CAAA;IAC5B,UAAU,EAAE,cAAc,CAAA;IAC1B,KAAK,EAAE,MAAM,CAAA;IACb,8EAA8E;IAC9E,YAAY,EAAE,UAAU,CAAA;CACxB;AAED,yDAAyD;AACzD,MAAM,WAAW,mBAAmB;IACnC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,yEAAyE;IACzE,IAAI,EAAE,UAAU,CAAA;IAChB,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,qBAAqB,EAAE,CAAA;CAChC;AAwKD,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,gBAAgB,EAAE,iBAAiB,CAkLnE,CAAA"}
@@ -1,313 +0,0 @@
1
- /**
2
- * Mandala (BRC-162) send to a BRC-169 handle, delivered per BRC-232.
3
- *
4
- * 1. Resolve the handle (`resolveHandle`): identity key + messagebox.
5
- * 2. When no single token output in `mandala <txid> <vout>` holds exactly `amount`,
6
- * split first: an ordinary, broadcast action spending token outputs into
7
- * an exact-`amount` output and a remainder, both back to the wallet under
8
- * `mandalaProtocol(tokenId)` in the token's basket.
9
- * 3. The protected send: one `createAction` spending only the exact output,
10
- * with one output, the recipient's token output, locked to the key
11
- * derived under `mandalaProtocol(tokenId)` with keyID
12
- * `<derivationPrefix> <derivationSuffix>` (fresh random base64) and
13
- * counterparty = the recipient. `noSend`, labels `mandala`,
14
- * `mandala <txid> <vout>` and `p nosend expiry seconds <n>` (BRC-177; the wallet
15
- * funds it). It is not broadcast: the recipient broadcasts by
16
- * internalizing (BRC-169 §6.1, BRC-232 rule 4).
17
- * 4. Delivery: a signed BRC-169 §7.3 envelope (DAG-CBOR, BRC-231 body over
18
- * BRC-104) to the resolved messagebox, box `mandala_inbox`, `payment:
19
- * null`. `content` is BRC-78 encryption (via `wallet.encrypt`) of a MIME
20
- * entity of type `application/vnd.metanet.transaction+cbor` whose DAG-CBOR
21
- * body is the BRC-232 delivery `{ txid, beef, outputs: [ basket insertion
22
- * ] }`; `contentHash` is the SHA-256 of the MIME bytes.
23
- *
24
- * When delivery fails the result carries the error with `txid` and `tx`, so
25
- * the caller can retry delivery or `abortAction` the send.
26
- */
27
- import { resolveHandle } from '@1sat/client';
28
- import { Mandala } from '@1sat/templates';
29
- import { MANDALA_INBOX, MANDALA_LABEL, METANET_SEND_EXPIRY_SECONDS, mandalaProtocol, mandalaTokenBasket, mandalaTokenLabel, } from '@1sat/types';
30
- import { TRANSACTION_CBOR_CONTENT_TYPE, encodeMimeEntity } from '@1sat/utils';
31
- import { Beef, P2PKH, PublicKey, Utils, } from '@bsv/sdk';
32
- import { encode as dagCborEncode } from '@ipld/dag-cbor';
33
- import { randomBase64, sendEnvelope } from '../metanet/deliver.js';
34
- import { executeTrackedAction } from '../utils/createTrackedAction.js';
35
- import { resolveDestination } from '../utils/resolveDestination.js';
36
- import { mandalaTokenOf, mandalaTokenOutpoint, mandalaWireId, } from './tokenId.js';
37
- /** Token amount a wallet output carries for `tokenId`, read from its locking script. */
38
- function tokenAmount(beef, output, tokenId) {
39
- const [txid, vout] = output.outpoint.split('.');
40
- const script = beef.findTxid(txid)?.tx?.outputs[Number(vout)]?.lockingScript;
41
- if (!script)
42
- return undefined;
43
- const token = Mandala.decode(script);
44
- // Authority outputs (amount 0) are not spent by a send.
45
- if (!token || token.amount === 0n)
46
- return undefined;
47
- return mandalaTokenOf(token, txid, Number(vout)) === tokenId
48
- ? token.amount
49
- : undefined;
50
- }
51
- /**
52
- * A token value output back to the wallet, in the token's basket, with a
53
- * fresh self-derived key; customInstructions carry only the derivation.
54
- */
55
- async function selfTokenOutput(ctx, tokenId, amount, outputDescription) {
56
- const self = await resolveDestination(ctx, { counterparty: 'self' }, { protocolID: mandalaProtocol(tokenId), keyIDPrefix: 'mandala' });
57
- return {
58
- lockingScript: Mandala.value(mandalaWireId(tokenId), amount, {
59
- lock: self.lockingScript,
60
- })
61
- .lock()
62
- .toHex(),
63
- satoshis: 1,
64
- outputDescription,
65
- basket: mandalaTokenBasket(tokenId),
66
- customInstructions: JSON.stringify(self.customInstructions),
67
- };
68
- }
69
- /** Spend wallet token outputs through the shared pipeline. */
70
- function spendTokens(ctx, p) {
71
- return executeTrackedAction(ctx.wallet, {
72
- description: p.description,
73
- labels: [...p.labels],
74
- inputBEEF: p.inputBEEF,
75
- inputs: p.inputs.map((i) => ({
76
- outpoint: i.outpoint,
77
- inputDescription: 'Mandala token input',
78
- unlockingScriptLength: 108,
79
- })),
80
- outputs: p.outputs,
81
- options: p.noSend
82
- ? { noSend: true, randomizeOutputs: false }
83
- : { randomizeOutputs: false },
84
- }, undefined, p.inputBEEF, undefined, {
85
- spends: p.inputs.map((i) => ({
86
- outpoint: i.outpoint,
87
- customInstructions: i.customInstructions,
88
- })),
89
- });
90
- }
91
- /**
92
- * Split token inputs into an exact `amount` output (vout 0) and a remainder,
93
- * both back to the wallet in the token's basket, broadcast normally. Returns
94
- * the exact output as the next input, with BEEF that carries it.
95
- */
96
- async function splitExact(ctx, p) {
97
- const exactOut = await selfTokenOutput(ctx, p.tokenId, p.amount, 'Mandala exact amount');
98
- // No remainder when the inputs sum to `amount` (an amount-0 Mandala
99
- // output would be an authority).
100
- const rest = p.change > 0n
101
- ? [await selfTokenOutput(ctx, p.tokenId, p.change, 'Mandala remainder')]
102
- : [];
103
- const result = await spendTokens(ctx, {
104
- description: `Split ${p.amount} Mandala tokens`,
105
- labels: p.labels,
106
- inputs: p.inputs,
107
- inputBEEF: p.inputBEEF,
108
- outputs: [exactOut, ...rest],
109
- noSend: false,
110
- });
111
- if (result.error)
112
- return { error: `split-failed: ${result.error}` };
113
- if (!result.txid || !result.tx)
114
- return { error: 'split-failed: no-transaction' };
115
- return {
116
- input: {
117
- outpoint: `${result.txid}.0`,
118
- customInstructions: exactOut.customInstructions,
119
- amount: p.amount,
120
- },
121
- beef: Beef.fromBinary(result.tx).toBinary(),
122
- };
123
- }
124
- /**
125
- * Build, sign and send the BRC-169 §7.3 envelope carrying a BRC-232 delivery
126
- * in its encrypted `content`.
127
- */
128
- async function deliverEnvelope(ctx, resolution, p) {
129
- const { memo, ...rest } = p.body;
130
- const body = memo === undefined ? rest : { memo, ...rest };
131
- const plaintext = Array.from(encodeMimeEntity(TRANSACTION_CBOR_CONTENT_TYPE, dagCborEncode(body)));
132
- return sendEnvelope(ctx.wallet, resolution, {
133
- senderIdentityKey: p.senderIdentityKey,
134
- plaintext,
135
- payment: null,
136
- messageBox: MANDALA_INBOX,
137
- });
138
- }
139
- export const sendMandala = {
140
- meta: {
141
- name: 'sendMandala',
142
- description: "Send Mandala (BRC-162) tokens to a BRC-169 handle: a protected noSend transaction delivered (BRC-232) in a signed envelope to the handle's mandala_inbox; the recipient broadcasts",
143
- category: 'tokens',
144
- inputSchema: {
145
- type: 'object',
146
- properties: {
147
- tokenId: {
148
- type: 'string',
149
- description: 'Token: the deploy outpoint, BRC-36 <txid>.<vout> (<txid>_<vout> accepted)',
150
- },
151
- amount: {
152
- type: 'string',
153
- description: 'Amount in raw units (string for bigint)',
154
- },
155
- destination: {
156
- type: 'object',
157
- description: '{ handle } — a BRC-169 handle (@handle@domain)',
158
- },
159
- expirySeconds: {
160
- type: 'integer',
161
- description: 'BRC-177 nosend expiry in seconds (default 31536000, one year)',
162
- },
163
- memo: {
164
- type: 'string',
165
- description: 'Optional memo carried in the delivery',
166
- },
167
- },
168
- required: ['tokenId', 'amount', 'destination'],
169
- },
170
- },
171
- async execute(ctx, input) {
172
- try {
173
- let tokenId;
174
- try {
175
- tokenId = mandalaTokenOutpoint(input.tokenId);
176
- }
177
- catch {
178
- return { error: 'invalid-token: expected <txid>.<vout>' };
179
- }
180
- const amount = BigInt(input.amount);
181
- if (amount <= 0n)
182
- return { error: 'amount-must-be-positive' };
183
- const basket = mandalaTokenBasket(tokenId);
184
- // 1. Resolve the handle; the recipient key is derived from it.
185
- const resolution = await resolveHandle(input.destination.handle);
186
- const listed = await ctx.wallet.listOutputs({
187
- basket,
188
- include: 'entire transactions',
189
- includeTags: true,
190
- includeCustomInstructions: true,
191
- limit: 10000,
192
- });
193
- if (!listed.BEEF)
194
- return { error: 'no-beef-available' };
195
- const beef = Beef.fromBinary(Array.from(listed.BEEF));
196
- // Spendable token outputs, amounts read from the script.
197
- const candidates = [];
198
- for (const o of listed.outputs) {
199
- const amt = tokenAmount(beef, o, tokenId);
200
- if (amt === undefined)
201
- continue;
202
- candidates.push({
203
- outpoint: o.outpoint,
204
- customInstructions: o.customInstructions,
205
- amount: amt,
206
- });
207
- }
208
- const labels = [MANDALA_LABEL, mandalaTokenLabel(tokenId)];
209
- // 2. The protected send spends exactly one output of exactly `amount`.
210
- let exact = candidates.find((c) => c.amount === amount);
211
- let inputBEEF = Array.from(listed.BEEF);
212
- if (!exact) {
213
- const inputs = [];
214
- let totalIn = 0n;
215
- for (const c of candidates) {
216
- if (totalIn >= amount)
217
- break;
218
- inputs.push(c);
219
- totalIn += c.amount;
220
- }
221
- if (totalIn < amount)
222
- return { error: 'insufficient-tokens' };
223
- const split = await splitExact(ctx, {
224
- tokenId,
225
- labels,
226
- inputs,
227
- inputBEEF,
228
- amount,
229
- change: totalIn - amount,
230
- });
231
- if ('error' in split)
232
- return { error: split.error };
233
- exact = split.input;
234
- inputBEEF = split.beef;
235
- }
236
- // 3. The recipient's output, BRC-29-style derivation under the token's protocol.
237
- const protocolID = mandalaProtocol(tokenId);
238
- const keyID = `${randomBase64()} ${randomBase64()}`;
239
- const { publicKey } = await ctx.wallet.getPublicKey({
240
- protocolID,
241
- keyID,
242
- counterparty: resolution.identityKey,
243
- });
244
- const recipientOutput = {
245
- lockingScript: Mandala.value(mandalaWireId(tokenId), amount, {
246
- lock: new P2PKH().lock(PublicKey.fromString(publicKey).toAddress(ctx.chain)),
247
- })
248
- .lock()
249
- .toHex(),
250
- satoshis: 1,
251
- outputDescription: 'Mandala tokens',
252
- };
253
- const expiry = input.expirySeconds ?? METANET_SEND_EXPIRY_SECONDS;
254
- const result = await spendTokens(ctx, {
255
- description: `Send ${amount} Mandala tokens`,
256
- labels: [...labels, `p nosend expiry seconds ${expiry}`],
257
- inputs: [exact],
258
- inputBEEF,
259
- outputs: [recipientOutput],
260
- noSend: true,
261
- });
262
- if (result.error)
263
- return { error: result.error };
264
- if (!result.txid || !result.tx)
265
- return { error: 'no-transaction' };
266
- // 4. Deliver.
267
- const { publicKey: senderIdentityKey } = await ctx.wallet.getPublicKey({
268
- identityKey: true,
269
- });
270
- let sent;
271
- try {
272
- sent = await deliverEnvelope(ctx, resolution, {
273
- senderIdentityKey,
274
- body: {
275
- memo: input.memo,
276
- txid: Uint8Array.from(Utils.toArray(result.txid, 'hex')),
277
- beef: Uint8Array.from(result.tx),
278
- outputs: [
279
- {
280
- outputIndex: 0,
281
- protocol: 'basket insertion',
282
- protocolID,
283
- keyID,
284
- counterparty: Uint8Array.from(Utils.toArray(senderIdentityKey, 'hex')),
285
- },
286
- ],
287
- },
288
- });
289
- }
290
- catch (error) {
291
- // The send exists as a noSend action: return it so the caller can
292
- // retry delivery or abortAction it.
293
- return {
294
- txid: result.txid,
295
- tx: result.tx,
296
- error: `delivery-failed: ${error instanceof Error ? error.message : String(error)}`,
297
- };
298
- }
299
- return {
300
- txid: result.txid,
301
- tx: result.tx,
302
- delivered: 'envelope',
303
- messageId: sent.messageId,
304
- };
305
- }
306
- catch (error) {
307
- return {
308
- error: error instanceof Error ? error.message : String(error),
309
- };
310
- }
311
- },
312
- };
313
- //# sourceMappingURL=send.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"send.js","sourceRoot":"","sources":["../../src/mandala/send.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAyB,aAAa,EAAE,MAAM,cAAc,CAAA;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EACN,aAAa,EACb,aAAa,EACb,2BAA2B,EAC3B,eAAe,EACf,kBAAkB,EAClB,iBAAiB,GACjB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC7E,OAAO,EACN,IAAI,EAEJ,KAAK,EACL,SAAS,EACT,KAAK,GAGL,MAAM,UAAU,CAAA;A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