@1sat/actions 0.0.230 → 0.0.232
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/dist/apply/opnsRegister.d.ts +12 -5
- package/dist/apply/opnsRegister.d.ts.map +1 -1
- package/dist/apply/opnsRegister.js +68 -10
- package/dist/apply/opnsRegister.js.map +1 -1
- package/dist/funding/index.d.ts +1 -0
- package/dist/funding/index.d.ts.map +1 -1
- package/dist/funding/index.js +1 -1
- package/dist/funding/index.js.map +1 -1
- package/dist/funding/walletFunding.d.ts +47 -0
- package/dist/funding/walletFunding.d.ts.map +1 -0
- package/dist/funding/walletFunding.js +162 -0
- package/dist/funding/walletFunding.js.map +1 -0
- package/dist/funding/walletFunding.test.d.ts +2 -0
- package/dist/funding/walletFunding.test.d.ts.map +1 -0
- package/dist/funding/walletFunding.test.js +225 -0
- package/dist/funding/walletFunding.test.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/mandala/deploy.d.ts +89 -0
- package/dist/mandala/deploy.d.ts.map +1 -0
- package/dist/mandala/deploy.js +226 -0
- package/dist/mandala/deploy.js.map +1 -0
- package/dist/mandala/deploy.test.d.ts +2 -0
- package/dist/mandala/deploy.test.d.ts.map +1 -0
- package/dist/mandala/deploy.test.js +281 -0
- package/dist/mandala/deploy.test.js.map +1 -0
- package/dist/mandala/index.d.ts +9 -0
- package/dist/mandala/index.d.ts.map +1 -0
- package/dist/mandala/index.js +17 -0
- package/dist/mandala/index.js.map +1 -0
- package/dist/mandala/receive.d.ts +58 -0
- package/dist/mandala/receive.d.ts.map +1 -0
- package/dist/mandala/receive.js +162 -0
- package/dist/mandala/receive.js.map +1 -0
- package/dist/mandala/send.d.ts +74 -0
- package/dist/mandala/send.d.ts.map +1 -0
- package/dist/mandala/send.js +313 -0
- package/dist/mandala/send.js.map +1 -0
- package/dist/mandala/send.test.d.ts +2 -0
- package/dist/mandala/send.test.d.ts.map +1 -0
- package/dist/mandala/send.test.js +515 -0
- package/dist/mandala/send.test.js.map +1 -0
- package/dist/mandala/tokenId.d.ts +21 -0
- package/dist/mandala/tokenId.d.ts.map +1 -0
- package/dist/mandala/tokenId.js +29 -0
- package/dist/mandala/tokenId.js.map +1 -0
- package/dist/metanet/brc78.d.ts +29 -0
- package/dist/metanet/brc78.d.ts.map +1 -0
- package/dist/metanet/brc78.js +60 -0
- package/dist/metanet/brc78.js.map +1 -0
- package/dist/metanet/deliver.d.ts +26 -0
- package/dist/metanet/deliver.d.ts.map +1 -0
- package/dist/metanet/deliver.js +34 -0
- package/dist/metanet/deliver.js.map +1 -0
- package/dist/metanet/envelope.d.ts +69 -0
- package/dist/metanet/envelope.d.ts.map +1 -0
- package/dist/metanet/envelope.js +86 -0
- package/dist/metanet/envelope.js.map +1 -0
- package/dist/metanet/envelope.test.d.ts +2 -0
- package/dist/metanet/envelope.test.d.ts.map +1 -0
- package/dist/metanet/envelope.test.js +106 -0
- package/dist/metanet/envelope.test.js.map +1 -0
- package/dist/metanet/inbox.d.ts +51 -0
- package/dist/metanet/inbox.d.ts.map +1 -0
- package/dist/metanet/inbox.js +100 -0
- package/dist/metanet/inbox.js.map +1 -0
- package/dist/metanet/index.d.ts +8 -0
- package/dist/metanet/index.d.ts.map +1 -0
- package/dist/metanet/index.js +9 -0
- package/dist/metanet/index.js.map +1 -0
- package/dist/metanet/receive.d.ts +50 -0
- package/dist/metanet/receive.d.ts.map +1 -0
- package/dist/metanet/receive.js +107 -0
- package/dist/metanet/receive.js.map +1 -0
- package/dist/metanet/relay.d.ts +37 -0
- package/dist/metanet/relay.d.ts.map +1 -0
- package/dist/metanet/relay.js +51 -0
- package/dist/metanet/relay.js.map +1 -0
- package/dist/opns/index.d.ts +65 -4
- package/dist/opns/index.d.ts.map +1 -1
- package/dist/opns/index.js +93 -34
- package/dist/opns/index.js.map +1 -1
- package/dist/opns/registerOpns.test.d.ts +2 -0
- package/dist/opns/registerOpns.test.d.ts.map +1 -0
- package/dist/opns/registerOpns.test.js +186 -0
- package/dist/opns/registerOpns.test.js.map +1 -0
- package/dist/payments/index.d.ts +32 -1
- package/dist/payments/index.d.ts.map +1 -1
- package/dist/payments/index.js +118 -6
- package/dist/payments/index.js.map +1 -1
- package/dist/payments/sendBsvHandle.test.d.ts +2 -0
- package/dist/payments/sendBsvHandle.test.d.ts.map +1 -0
- package/dist/payments/sendBsvHandle.test.js +478 -0
- package/dist/payments/sendBsvHandle.test.js.map +1 -0
- package/package.json +8 -7
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collect BRC-169 payments from the wallet's `metanet_inbox`.
|
|
3
|
+
*
|
|
4
|
+
* For each message listed (BRC-231 over BRC-104) the shared inbox steps
|
|
5
|
+
* decode the §7.3 DAG-CBOR envelope, verify its §7.2 signature against
|
|
6
|
+
* `sender.identityKey`, decrypt the BRC-78 `content`, check `contentHash`
|
|
7
|
+
* and parse the MIME entity (see `processInbox`). Then:
|
|
8
|
+
*
|
|
9
|
+
* - `payment` set (BRC-169 §6.1): internalize its Atomic BEEF as a BRC-29
|
|
10
|
+
* `wallet payment` of output 0, remittance `{ derivationPrefix,
|
|
11
|
+
* derivationSuffix, senderIdentityKey: sender.identityKey }`, label
|
|
12
|
+
* `metanet payment`, the memo in the description when `content` is
|
|
13
|
+
* `text/plain`;
|
|
14
|
+
* - `payment` null and `content` a BRC-232 transaction delivery: processed as
|
|
15
|
+
* `syncMandalaInbox` processes it.
|
|
16
|
+
*
|
|
17
|
+
* A message is acknowledged only after its internalize succeeds. Anything
|
|
18
|
+
* else (JSON envelopes, a bad signature or hash, a payment protocol other
|
|
19
|
+
* than BRC-29, a payment whose content is a transaction delivery, a message
|
|
20
|
+
* with nothing to internalize) is left unacknowledged and reported.
|
|
21
|
+
*/
|
|
22
|
+
import type { Action } from '../types.js';
|
|
23
|
+
import { type InboxSkip } from './inbox.js';
|
|
24
|
+
/** Label on internalized handle payments */
|
|
25
|
+
export declare const METANET_PAYMENT_LABEL = "metanet payment";
|
|
26
|
+
export interface SyncMetanetInboxInput {
|
|
27
|
+
/** MessageBox server URL (default: "https://messagebox.1sat.app") */
|
|
28
|
+
messageboxUrl?: string;
|
|
29
|
+
}
|
|
30
|
+
/** A message internalized and acknowledged. */
|
|
31
|
+
export interface MetanetInboxReceipt {
|
|
32
|
+
messageId: string;
|
|
33
|
+
txid: string;
|
|
34
|
+
/** Sender identity key, hex */
|
|
35
|
+
sender: string;
|
|
36
|
+
/** `payment.satoshis` as the envelope states it (payments only) */
|
|
37
|
+
satoshis?: number;
|
|
38
|
+
/** The `text/plain` content (payments only) */
|
|
39
|
+
memo?: string;
|
|
40
|
+
/** Mandala tokens received (BRC-232 deliveries only) */
|
|
41
|
+
tokenIds: string[];
|
|
42
|
+
}
|
|
43
|
+
export interface SyncMetanetInboxResult {
|
|
44
|
+
received: MetanetInboxReceipt[];
|
|
45
|
+
/** Messages left unacknowledged */
|
|
46
|
+
skipped: InboxSkip[];
|
|
47
|
+
error?: string;
|
|
48
|
+
}
|
|
49
|
+
export declare const syncMetanetInbox: Action<SyncMetanetInboxInput, SyncMetanetInboxResult>;
|
|
50
|
+
//# sourceMappingURL=receive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"receive.d.ts","sourceRoot":"","sources":["../../src/metanet/receive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,EAAE,KAAK,SAAS,EAAgC,MAAM,YAAY,CAAA;AAEzE,4CAA4C;AAC5C,eAAO,MAAM,qBAAqB,oBAAoB,CAAA;AAEtD,MAAM,WAAW,qBAAqB;IACrC,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,+CAA+C;AAC/C,MAAM,WAAW,mBAAmB;IACnC,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,+BAA+B;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,mEAAmE;IACnE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,+CAA+C;IAC/C,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,wDAAwD;IACxD,QAAQ,EAAE,MAAM,EAAE,CAAA;CAClB;AAED,MAAM,WAAW,sBAAsB;IACtC,QAAQ,EAAE,mBAAmB,EAAE,CAAA;IAC/B,mCAAmC;IACnC,OAAO,EAAE,SAAS,EAAE,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;CACd;AAqDD,eAAO,MAAM,gBAAgB,EAAE,MAAM,CACpC,qBAAqB,EACrB,sBAAsB,CAiEtB,CAAA"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collect BRC-169 payments from the wallet's `metanet_inbox`.
|
|
3
|
+
*
|
|
4
|
+
* For each message listed (BRC-231 over BRC-104) the shared inbox steps
|
|
5
|
+
* decode the §7.3 DAG-CBOR envelope, verify its §7.2 signature against
|
|
6
|
+
* `sender.identityKey`, decrypt the BRC-78 `content`, check `contentHash`
|
|
7
|
+
* and parse the MIME entity (see `processInbox`). Then:
|
|
8
|
+
*
|
|
9
|
+
* - `payment` set (BRC-169 §6.1): internalize its Atomic BEEF as a BRC-29
|
|
10
|
+
* `wallet payment` of output 0, remittance `{ derivationPrefix,
|
|
11
|
+
* derivationSuffix, senderIdentityKey: sender.identityKey }`, label
|
|
12
|
+
* `metanet payment`, the memo in the description when `content` is
|
|
13
|
+
* `text/plain`;
|
|
14
|
+
* - `payment` null and `content` a BRC-232 transaction delivery: processed as
|
|
15
|
+
* `syncMandalaInbox` processes it.
|
|
16
|
+
*
|
|
17
|
+
* A message is acknowledged only after its internalize succeeds. Anything
|
|
18
|
+
* else (JSON envelopes, a bad signature or hash, a payment protocol other
|
|
19
|
+
* than BRC-29, a payment whose content is a transaction delivery, a message
|
|
20
|
+
* with nothing to internalize) is left unacknowledged and reported.
|
|
21
|
+
*/
|
|
22
|
+
import { BRC29_PROTOCOL_ID, METANET_INBOX } from '@1sat/types';
|
|
23
|
+
import { TRANSACTION_CBOR_CONTENT_TYPE, mediaType } from '@1sat/utils';
|
|
24
|
+
import { Beef, Utils } from '@bsv/sdk';
|
|
25
|
+
import { internalizeTransactionDelivery } from '../mandala/receive.js';
|
|
26
|
+
import { InboxSkipError, processInbox } from './inbox.js';
|
|
27
|
+
/** Label on internalized handle payments */
|
|
28
|
+
export const METANET_PAYMENT_LABEL = 'metanet payment';
|
|
29
|
+
const BRC29_PROTOCOL = BRC29_PROTOCOL_ID[1];
|
|
30
|
+
/** Internalize a §7.3 `payment` as a BRC-29 wallet payment of output 0. */
|
|
31
|
+
async function internalizeEnvelopePayment(wallet, payment, sender, memo) {
|
|
32
|
+
if (!(payment.protocol instanceof Uint8Array) ||
|
|
33
|
+
Utils.toUTF8(Array.from(payment.protocol)) !== BRC29_PROTOCOL) {
|
|
34
|
+
throw new InboxSkipError('payment protocol is not BRC-29');
|
|
35
|
+
}
|
|
36
|
+
if (!(payment.derivationPrefix instanceof Uint8Array) ||
|
|
37
|
+
!(payment.derivationSuffix instanceof Uint8Array) ||
|
|
38
|
+
!(payment.beef instanceof Uint8Array)) {
|
|
39
|
+
throw new InboxSkipError('malformed payment');
|
|
40
|
+
}
|
|
41
|
+
const beef = Beef.fromBinary(Array.from(payment.beef));
|
|
42
|
+
const txid = beef.atomicTxid ?? beef.txs[beef.txs.length - 1]?.tx?.id('hex');
|
|
43
|
+
if (!txid)
|
|
44
|
+
throw new InboxSkipError('payment beef has no transaction');
|
|
45
|
+
await wallet.internalizeAction({
|
|
46
|
+
tx: beef.toBinaryAtomic(txid),
|
|
47
|
+
outputs: [
|
|
48
|
+
{
|
|
49
|
+
outputIndex: 0,
|
|
50
|
+
protocol: 'wallet payment',
|
|
51
|
+
paymentRemittance: {
|
|
52
|
+
derivationPrefix: Utils.toBase64(Array.from(payment.derivationPrefix)),
|
|
53
|
+
derivationSuffix: Utils.toBase64(Array.from(payment.derivationSuffix)),
|
|
54
|
+
senderIdentityKey: sender,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
labels: [METANET_PAYMENT_LABEL],
|
|
59
|
+
description: (memo ? `Metanet payment: ${memo}` : 'Metanet payment').slice(0, 50),
|
|
60
|
+
});
|
|
61
|
+
return txid;
|
|
62
|
+
}
|
|
63
|
+
export const syncMetanetInbox = {
|
|
64
|
+
meta: {
|
|
65
|
+
name: 'syncMetanetInbox',
|
|
66
|
+
description: 'Collect BRC-169 handle payments (and BRC-232 deliveries) from the metanet_inbox message box and internalize them',
|
|
67
|
+
category: 'sync',
|
|
68
|
+
inputSchema: {
|
|
69
|
+
type: 'object',
|
|
70
|
+
properties: {
|
|
71
|
+
messageboxUrl: {
|
|
72
|
+
type: 'string',
|
|
73
|
+
description: 'MessageBox server URL (default: "https://messagebox.1sat.app")',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
requiresServices: false,
|
|
78
|
+
},
|
|
79
|
+
async execute(ctx, input) {
|
|
80
|
+
return processInbox(ctx.wallet, input.messageboxUrl, METANET_INBOX, async ({ env, sender, entity }, msg) => {
|
|
81
|
+
const type = mediaType(entity.contentType);
|
|
82
|
+
if (env.payment) {
|
|
83
|
+
if (type === TRANSACTION_CBOR_CONTENT_TYPE) {
|
|
84
|
+
throw new InboxSkipError('a payment with transaction-delivery content is not supported');
|
|
85
|
+
}
|
|
86
|
+
const memo = type === 'text/plain'
|
|
87
|
+
? Utils.toUTF8(Array.from(entity.body))
|
|
88
|
+
: undefined;
|
|
89
|
+
const txid = await internalizeEnvelopePayment(ctx.wallet, env.payment, sender, memo);
|
|
90
|
+
return {
|
|
91
|
+
messageId: msg.messageId,
|
|
92
|
+
txid,
|
|
93
|
+
sender,
|
|
94
|
+
satoshis: env.payment.satoshis,
|
|
95
|
+
memo,
|
|
96
|
+
tokenIds: [],
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (type === TRANSACTION_CBOR_CONTENT_TYPE) {
|
|
100
|
+
const { txid, tokenIds } = await internalizeTransactionDelivery(ctx.wallet, entity.body);
|
|
101
|
+
return { messageId: msg.messageId, txid, sender, tokenIds };
|
|
102
|
+
}
|
|
103
|
+
throw new InboxSkipError(`nothing to internalize: no payment, content type ${entity.contentType}`);
|
|
104
|
+
});
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=receive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"receive.js","sourceRoot":"","sources":["../../src/metanet/receive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC9D,OAAO,EAAE,6BAA6B,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACtE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAwB,MAAM,UAAU,CAAA;AAC5D,OAAO,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAA;AAGtE,OAAO,EAAkB,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEzE,4CAA4C;AAC5C,MAAM,CAAC,MAAM,qBAAqB,GAAG,iBAAiB,CAAA;AA4BtD,MAAM,cAAc,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAA;AAE3C,2EAA2E;AAC3E,KAAK,UAAU,0BAA0B,CACxC,MAAkD,EAClD,OAAwB,EACxB,MAAc,EACd,IAAwB;IAExB,IACC,CAAC,CAAC,OAAO,CAAC,QAAQ,YAAY,UAAU,CAAC;QACzC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,cAAc,EAC5D,CAAC;QACF,MAAM,IAAI,cAAc,CAAC,gCAAgC,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oBACJ,QAAQ,EAAE,EAAE;iBACZ,CAAA;YACF,CAAC;YACD,IAAI,IAAI,KAAK,6BAA6B,EAAE,CAAC;gBAC5C,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,MAAM,8BAA8B,CAC9D,GAAG,CAAC,MAAM,EACV,MAAM,CAAC,IAAI,CACX,CAAA;gBACD,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAA;YAC5D,CAAC;YACD,MAAM,IAAI,cAAc,CACvB,oDAAoD,MAAM,CAAC,WAAW,EAAE,CACxE,CAAA;QACF,CAAC,CACD,CAAA;IACF,CAAC;CACD,CAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BRC-33 message relay in the BRC-231 binary encoding, over BRC-104
|
|
3
|
+
* (AuthFetch): requests and responses are DAG-CBOR, the message body and
|
|
4
|
+
* identity keys are byte strings.
|
|
5
|
+
*
|
|
6
|
+
* - `POST /sendMessage` `{ message: { recipient: bstr(33), messageBox, body: bstr } }`
|
|
7
|
+
* → `{ status, messageId }`
|
|
8
|
+
* - `POST /listMessages` `{ messageBox }`
|
|
9
|
+
* → `{ status, messages: [ { messageId, body: bstr, sender: bstr(33) } ] }`
|
|
10
|
+
* - `POST /acknowledgeMessage` `{ messageIds }` → `{ status }`
|
|
11
|
+
*/
|
|
12
|
+
import { type WalletInterface } from '@bsv/sdk';
|
|
13
|
+
/** A listed BRC-231 message. */
|
|
14
|
+
export interface CborMessage {
|
|
15
|
+
messageId: string;
|
|
16
|
+
body: Uint8Array;
|
|
17
|
+
sender: Uint8Array;
|
|
18
|
+
}
|
|
19
|
+
export declare function sendCborMessage(wallet: WalletInterface, messagebox: string, recipient: string, messageBox: string, body: Uint8Array): Promise<{
|
|
20
|
+
status: string;
|
|
21
|
+
messageId: string;
|
|
22
|
+
}>;
|
|
23
|
+
export declare function listCborMessages(wallet: WalletInterface, messagebox: string, messageBox: string): Promise<CborMessage[]>;
|
|
24
|
+
export declare function acknowledgeCborMessages(wallet: WalletInterface, messagebox: string, messageIds: string[]): Promise<{
|
|
25
|
+
status: string;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* The relay calls the BRC-169 envelope actions make (Mandala sends, handle
|
|
29
|
+
* payments, inbox syncs), gathered in one object so a host or a test can
|
|
30
|
+
* substitute the transport.
|
|
31
|
+
*/
|
|
32
|
+
export declare const messageRelay: {
|
|
33
|
+
sendCborMessage: typeof sendCborMessage;
|
|
34
|
+
listCborMessages: typeof listCborMessages;
|
|
35
|
+
acknowledgeCborMessages: typeof acknowledgeCborMessages;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=relay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relay.d.ts","sourceRoot":"","sources":["../../src/metanet/relay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAoB,KAAK,eAAe,EAAE,MAAM,UAAU,CAAA;AAMjE,gCAAgC;AAChC,MAAM,WAAW,WAAW;IAC3B,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,UAAU,CAAA;IAChB,MAAM,EAAE,UAAU,CAAA;CAClB;AAsBD,wBAAsB,eAAe,CACpC,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,UAAU,GACd,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAQhD;AAED,wBAAsB,gBAAgB,CACrC,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,GAChB,OAAO,CAAC,WAAW,EAAE,CAAC,CAQxB;AAED,wBAAsB,uBAAuB,CAC5C,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAAE,GAClB,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAE7B;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY;;;;CAIxB,CAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BRC-33 message relay in the BRC-231 binary encoding, over BRC-104
|
|
3
|
+
* (AuthFetch): requests and responses are DAG-CBOR, the message body and
|
|
4
|
+
* identity keys are byte strings.
|
|
5
|
+
*
|
|
6
|
+
* - `POST /sendMessage` `{ message: { recipient: bstr(33), messageBox, body: bstr } }`
|
|
7
|
+
* → `{ status, messageId }`
|
|
8
|
+
* - `POST /listMessages` `{ messageBox }`
|
|
9
|
+
* → `{ status, messages: [ { messageId, body: bstr, sender: bstr(33) } ] }`
|
|
10
|
+
* - `POST /acknowledgeMessage` `{ messageIds }` → `{ status }`
|
|
11
|
+
*/
|
|
12
|
+
import { AuthFetch, Utils } from '@bsv/sdk';
|
|
13
|
+
import { decode as dagCborDecode, encode as dagCborEncode, } from '@ipld/dag-cbor';
|
|
14
|
+
async function postCbor(wallet, messagebox, path, request) {
|
|
15
|
+
const res = await new AuthFetch(wallet).fetch(`${messagebox.replace(/\/+$/, '')}${path}`, {
|
|
16
|
+
method: 'POST',
|
|
17
|
+
headers: { 'Content-Type': 'application/cbor' },
|
|
18
|
+
body: dagCborEncode(request),
|
|
19
|
+
});
|
|
20
|
+
if (!res.ok) {
|
|
21
|
+
throw new Error(`${path.slice(1)} ${res.status}`);
|
|
22
|
+
}
|
|
23
|
+
return dagCborDecode(new Uint8Array(await res.arrayBuffer()));
|
|
24
|
+
}
|
|
25
|
+
export async function sendCborMessage(wallet, messagebox, recipient, messageBox, body) {
|
|
26
|
+
return postCbor(wallet, messagebox, '/sendMessage', {
|
|
27
|
+
message: {
|
|
28
|
+
recipient: Uint8Array.from(Utils.toArray(recipient, 'hex')),
|
|
29
|
+
messageBox,
|
|
30
|
+
body,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
export async function listCborMessages(wallet, messagebox, messageBox) {
|
|
35
|
+
const res = await postCbor(wallet, messagebox, '/listMessages', { messageBox });
|
|
36
|
+
return res.messages ?? [];
|
|
37
|
+
}
|
|
38
|
+
export async function acknowledgeCborMessages(wallet, messagebox, messageIds) {
|
|
39
|
+
return postCbor(wallet, messagebox, '/acknowledgeMessage', { messageIds });
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The relay calls the BRC-169 envelope actions make (Mandala sends, handle
|
|
43
|
+
* payments, inbox syncs), gathered in one object so a host or a test can
|
|
44
|
+
* substitute the transport.
|
|
45
|
+
*/
|
|
46
|
+
export const messageRelay = {
|
|
47
|
+
sendCborMessage,
|
|
48
|
+
listCborMessages,
|
|
49
|
+
acknowledgeCborMessages,
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=relay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relay.js","sourceRoot":"","sources":["../../src/metanet/relay.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAwB,MAAM,UAAU,CAAA;AACjE,OAAO,EACN,MAAM,IAAI,aAAa,EACvB,MAAM,IAAI,aAAa,GACvB,MAAM,gBAAgB,CAAA;AASvB,KAAK,UAAU,QAAQ,CACtB,MAAuB,EACvB,UAAkB,EAClB,IAAY,EACZ,OAAgB;IAEhB,MAAM,GAAG,GAAG,MAAM,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC,KAAK,CAC5C,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,EAC1C;QACC,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/C,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC;KAC5B,C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
20
20
|
/** Tracking id of the OpNS UTXO in the OPNS basket */
|
|
21
21
|
id: string;
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
/** Inscription carried on the name coin after the PushDrop fields. */
|
|
24
|
+
export interface OpnsInscription {
|
|
25
|
+
contentType: string;
|
|
26
|
+
content: number[] | Uint8Array;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The `profile` written on the name — same members as the on-chain DAG-CBOR
|
|
30
|
+
* map; `avatar` is given as an outpoint and stored as its 36 bytes.
|
|
31
|
+
*/
|
|
32
|
+
export interface OpnsProfile {
|
|
24
33
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
34
|
+
* BRC-169 ecosystem domain the identity is reached at (e.g. `1sat.name`).
|
|
35
|
+
* Written exactly as given — not validated; fix a typo by republishing.
|
|
36
|
+
* Readers go `https://<domain>/manifest.json`.
|
|
27
37
|
*/
|
|
28
|
-
|
|
38
|
+
domain: string;
|
|
39
|
+
/**
|
|
40
|
+
* Presentation name (served by paymail public-profile). The OpNS name is
|
|
41
|
+
* the unique value; this is decoration.
|
|
42
|
+
*/
|
|
43
|
+
name?: string;
|
|
29
44
|
/** Origin outpoint (`txid_vout`) of an on-chain image ordinal */
|
|
30
45
|
avatar?: string;
|
|
31
46
|
}
|
|
47
|
+
export interface RegisterOpnsRequest extends OpnsIdInput {
|
|
48
|
+
profile: OpnsProfile;
|
|
49
|
+
/**
|
|
50
|
+
* Optional inscription envelope appended after the PushDrop lock. ORDFS
|
|
51
|
+
* records it as a new rev of the name's origin (`/<origin>:-1`). The
|
|
52
|
+
* action does not interpret the content type.
|
|
53
|
+
*/
|
|
54
|
+
inscription?: OpnsInscription;
|
|
55
|
+
}
|
|
32
56
|
export type DeregisterOpnsRequest = OpnsIdInput;
|
|
33
57
|
export interface SellOpnsRequest extends OpnsIdInput {
|
|
34
58
|
price: number;
|
|
@@ -75,6 +99,43 @@ export interface InternalizeOpnsResult {
|
|
|
75
99
|
}
|
|
76
100
|
export declare const listOpns: Action<ListOpnsInput, ListOpnsResult>;
|
|
77
101
|
export declare const internalizeOpns: Action<InternalizeOpnsInput, InternalizeOpnsResult>;
|
|
102
|
+
/**
|
|
103
|
+
* Publish an OpNS name: lock the name coin in a signed PushDrop (the plain
|
|
104
|
+
* template) whose fields are key/value pairs
|
|
105
|
+
* `["identity", <identity key>, "profile", <dag-cbor {domain, name?, avatar?}>, <sig>]`.
|
|
106
|
+
* The field codecs are in `@1sat/utils`; this action owns the layout (see
|
|
107
|
+
* `docs/protocols/opns-paymail-bind.md`).
|
|
108
|
+
*
|
|
109
|
+
* With `inscription`, the output script is that PushDrop lock followed by a
|
|
110
|
+
* standard 1-sat inscription envelope, so ORDFS serves the content as the
|
|
111
|
+
* name's latest rev (`/<origin>:-1`). The action is ignorant of the content
|
|
112
|
+
* type. Publishing a release or state is an `ordfs/dir` whose `"."` entry is
|
|
113
|
+
* the root outpoint:
|
|
114
|
+
*
|
|
115
|
+
* ```ts
|
|
116
|
+
* import { DIR_CONTENT_TYPE, DIR_VERSION, dirEncode } from '@1sat/actions'
|
|
117
|
+
* await registerOpns.execute(ctx, {
|
|
118
|
+
* id,
|
|
119
|
+
* profile: { domain: '1sat.name' },
|
|
120
|
+
* inscription: {
|
|
121
|
+
* contentType: DIR_CONTENT_TYPE, // 'ordfs/dir'
|
|
122
|
+
* content: dirEncode({
|
|
123
|
+
* version: DIR_VERSION,
|
|
124
|
+
* entries: [{
|
|
125
|
+
* name: new TextEncoder().encode('.'),
|
|
126
|
+
* isDir: true,
|
|
127
|
+
* ref: { kind: 'outpoint', txid: rootTxid, vout: 0 },
|
|
128
|
+
* }],
|
|
129
|
+
* }),
|
|
130
|
+
* },
|
|
131
|
+
* })
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* Two phases: the action emits the complete script with a zeroed signature
|
|
135
|
+
* field (and the envelope already appended); `applyOpnsRegister` finds that
|
|
136
|
+
* placeholder push and replaces it with the real signature. Nothing else in
|
|
137
|
+
* the script changes, so the envelope simply stays where it is.
|
|
138
|
+
*/
|
|
78
139
|
export declare const registerOpns: Action<RegisterOpnsRequest, OpnsOperationResponse>;
|
|
79
140
|
export declare const deregisterOpns: Action<DeregisterOpnsRequest, OpnsOperationResponse>;
|
|
80
141
|
export declare const sellOpns: Action<SellOpnsRequest, OpnsOperationResponse>;
|
package/dist/opns/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/opns/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/opns/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAkBH,OAAO,EACN,KAAK,IAAI,EAOT,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,MAAM,UAAU,CAAA;AASjB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAA;AACnE,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAiB,MAAM,aAAa,CAAA;AAavE,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAM/C,MAAM,WAAW,qBAAqB;IACrC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,EAAE,CAAC,EAAE,MAAM,EAAE,CAAA;IACb,UAAU,CAAC,EAAE,uBAAuB,EAAE,CAAA;IACtC,KAAK,CAAC,EAAE,MAAM,CAAA;CACd;AAED,0EAA0E;AAC1E,MAAM,WAAW,WAAY,SAAQ,aAAa;IACjD,sDAAsD;IACtD,EAAE,EAAE,MAAM,CAAA;CACV;AAED,sEAAsE;AACtE,MAAM,WAAW,eAAe;IAC/B,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,EAAE,GAAG,UAAU,CAAA;CAC9B;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC3B;;;;OAIG;IACH,MAAM,EAAE,MAA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AE,MAAM,CAAC,cAAc,EAAE,qBAAqB,CAoCjE,CAAA;AAED,eAAO,MAAM,WAAW,wSASvB,CAAA"}
|
package/dist/opns/index.js
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
* Self-moves: id → one loadBasketOutputBeef → ordinalSeedTags + domain tags.
|
|
6
6
|
* Ingress (internalizeOpns / buyOpns) stamps full tags including id:.
|
|
7
7
|
*/
|
|
8
|
-
import { OpNS, OrdLockV2, outpointToBytes } from '@1sat/templates';
|
|
9
|
-
import { OPNS_BASKET, OPNS_PUBLISHED_TAG, OPNS_REGISTER_COUNTERPARTY, OPNS_REGISTER_SIG_PLACEHOLDER_LEN, ORDLOCK_V2_TAG, P1SAT_PROTOCOL, buildInputAssetLabel, formatOrdinalOutpoint, opnsRegisterKeyId, readAssetIdTag, } from '@1sat/types';
|
|
8
|
+
import { Inscription, OpNS, OrdLockV2, outpointToBytes } from '@1sat/templates';
|
|
9
|
+
import { IDENTITY_FIELD, OPNS_BASKET, OPNS_PUBLISHED_TAG, OPNS_REGISTER_COUNTERPARTY, OPNS_REGISTER_SIG_PLACEHOLDER_LEN, ORDLOCK_V2_TAG, P1SAT_PROTOCOL, PROFILE_FIELD, buildInputAssetLabel, formatOrdinalOutpoint, opnsRegisterKeyId, readAssetIdTag, } from '@1sat/types';
|
|
10
|
+
import { encodeProfile } from '@1sat/utils';
|
|
10
11
|
import { P2PKH, PublicKey, PushDrop, Transaction, Utils, } from '@bsv/sdk';
|
|
11
12
|
import { prepareP1SatArgs } from '../apply/index.js';
|
|
12
13
|
import { buildOrdLockScript, buildOrdinalTransferDelivery, buyOrdinal, defaultPayAddress, deriveCancelAddressInternal, } from '../ordinals/index.js';
|
|
@@ -17,24 +18,6 @@ import { ordinalSeedTags } from '../utils/ordinalSeedTags.js';
|
|
|
17
18
|
import { ordLockCancelUnlockLength } from '../utils/ordlockCancelLength.js';
|
|
18
19
|
import { unlockingScriptLengthForInstructions } from '../utils/signOrdinalInput.js';
|
|
19
20
|
const OPNS_CONTENT_TYPE = 'application/op-ns';
|
|
20
|
-
/**
|
|
21
|
-
* Presentation slots published after the identity key: slot 1 display name
|
|
22
|
-
* (utf8), slot 2 avatar origin outpoint (36 bytes). Slot 1 is an empty push
|
|
23
|
-
* when only an avatar is set; trailing unset slots are omitted.
|
|
24
|
-
*/
|
|
25
|
-
function profileFields(profileName, avatar) {
|
|
26
|
-
const displayName = profileName?.trim() ?? '';
|
|
27
|
-
const origin = avatar?.trim() ?? '';
|
|
28
|
-
if (!displayName && !origin)
|
|
29
|
-
return [];
|
|
30
|
-
const nameField = displayName ? Utils.toArray(displayName, 'utf8') : [];
|
|
31
|
-
if (!origin)
|
|
32
|
-
return [nameField];
|
|
33
|
-
const avatarField = outpointToBytes(formatOrdinalOutpoint(origin));
|
|
34
|
-
if (!avatarField)
|
|
35
|
-
throw new Error(`invalid avatar outpoint: ${origin}`);
|
|
36
|
-
return [nameField, avatarField];
|
|
37
|
-
}
|
|
38
21
|
export { opnsRegisterKeyId } from '@1sat/types';
|
|
39
22
|
// ============================================================================
|
|
40
23
|
// Helpers
|
|
@@ -217,25 +200,82 @@ export const internalizeOpns = {
|
|
|
217
200
|
// ============================================================================
|
|
218
201
|
// register / deregister
|
|
219
202
|
// ============================================================================
|
|
203
|
+
/**
|
|
204
|
+
* Publish an OpNS name: lock the name coin in a signed PushDrop (the plain
|
|
205
|
+
* template) whose fields are key/value pairs
|
|
206
|
+
* `["identity", <identity key>, "profile", <dag-cbor {domain, name?, avatar?}>, <sig>]`.
|
|
207
|
+
* The field codecs are in `@1sat/utils`; this action owns the layout (see
|
|
208
|
+
* `docs/protocols/opns-paymail-bind.md`).
|
|
209
|
+
*
|
|
210
|
+
* With `inscription`, the output script is that PushDrop lock followed by a
|
|
211
|
+
* standard 1-sat inscription envelope, so ORDFS serves the content as the
|
|
212
|
+
* name's latest rev (`/<origin>:-1`). The action is ignorant of the content
|
|
213
|
+
* type. Publishing a release or state is an `ordfs/dir` whose `"."` entry is
|
|
214
|
+
* the root outpoint:
|
|
215
|
+
*
|
|
216
|
+
* ```ts
|
|
217
|
+
* import { DIR_CONTENT_TYPE, DIR_VERSION, dirEncode } from '@1sat/actions'
|
|
218
|
+
* await registerOpns.execute(ctx, {
|
|
219
|
+
* id,
|
|
220
|
+
* profile: { domain: '1sat.name' },
|
|
221
|
+
* inscription: {
|
|
222
|
+
* contentType: DIR_CONTENT_TYPE, // 'ordfs/dir'
|
|
223
|
+
* content: dirEncode({
|
|
224
|
+
* version: DIR_VERSION,
|
|
225
|
+
* entries: [{
|
|
226
|
+
* name: new TextEncoder().encode('.'),
|
|
227
|
+
* isDir: true,
|
|
228
|
+
* ref: { kind: 'outpoint', txid: rootTxid, vout: 0 },
|
|
229
|
+
* }],
|
|
230
|
+
* }),
|
|
231
|
+
* },
|
|
232
|
+
* })
|
|
233
|
+
* ```
|
|
234
|
+
*
|
|
235
|
+
* Two phases: the action emits the complete script with a zeroed signature
|
|
236
|
+
* field (and the envelope already appended); `applyOpnsRegister` finds that
|
|
237
|
+
* placeholder push and replaces it with the real signature. Nothing else in
|
|
238
|
+
* the script changes, so the envelope simply stays where it is.
|
|
239
|
+
*/
|
|
220
240
|
export const registerOpns = {
|
|
221
241
|
meta: {
|
|
222
242
|
name: 'registerOpns',
|
|
223
|
-
description: 'Bind BRC-100 identity key to an OpNS name via signed PushDrop',
|
|
243
|
+
description: 'Bind BRC-100 identity key to an OpNS name via signed PushDrop identity + profile fields, optionally with an inscription',
|
|
224
244
|
category: 'opns',
|
|
225
245
|
inputSchema: {
|
|
226
246
|
type: 'object',
|
|
227
247
|
properties: {
|
|
228
248
|
id: { type: 'string', description: 'OPNS basket tracking id' },
|
|
229
|
-
|
|
230
|
-
type: '
|
|
231
|
-
description: '
|
|
249
|
+
profile: {
|
|
250
|
+
type: 'object',
|
|
251
|
+
description: 'Profile written on the name',
|
|
252
|
+
properties: {
|
|
253
|
+
domain: {
|
|
254
|
+
type: 'string',
|
|
255
|
+
description: 'BRC-169 ecosystem domain, written as given (e.g. 1sat.name)',
|
|
256
|
+
},
|
|
257
|
+
name: {
|
|
258
|
+
type: 'string',
|
|
259
|
+
description: 'Presentation name for paymail public-profile',
|
|
260
|
+
},
|
|
261
|
+
avatar: {
|
|
262
|
+
type: 'string',
|
|
263
|
+
description: 'Origin outpoint (txid_vout) of an on-chain image ordinal',
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
required: ['domain'],
|
|
232
267
|
},
|
|
233
|
-
|
|
234
|
-
type: '
|
|
235
|
-
description: '
|
|
268
|
+
inscription: {
|
|
269
|
+
type: 'object',
|
|
270
|
+
description: 'Optional inscription appended after the PushDrop (any content type)',
|
|
271
|
+
properties: {
|
|
272
|
+
contentType: { type: 'string' },
|
|
273
|
+
content: { type: 'array', items: { type: 'integer' } },
|
|
274
|
+
},
|
|
275
|
+
required: ['contentType', 'content'],
|
|
236
276
|
},
|
|
237
277
|
},
|
|
238
|
-
required: ['id'],
|
|
278
|
+
required: ['id', 'profile'],
|
|
239
279
|
},
|
|
240
280
|
},
|
|
241
281
|
async execute(ctx, input) {
|
|
@@ -248,16 +288,35 @@ export const registerOpns = {
|
|
|
248
288
|
return { error: 'missing-custom-instructions' };
|
|
249
289
|
}
|
|
250
290
|
const keyID = opnsRegisterKeyId(output.outpoint);
|
|
251
|
-
const { publicKey:
|
|
291
|
+
const { publicKey: identityKey } = await ctx.wallet.getPublicKey({
|
|
252
292
|
identityKey: true,
|
|
253
293
|
});
|
|
294
|
+
const avatarOutpoint = input.profile?.avatar;
|
|
295
|
+
let avatar;
|
|
296
|
+
if (avatarOutpoint?.trim()) {
|
|
297
|
+
const bytes = outpointToBytes(formatOrdinalOutpoint(avatarOutpoint));
|
|
298
|
+
if (!bytes)
|
|
299
|
+
throw new Error(`invalid avatar outpoint: ${avatarOutpoint}`);
|
|
300
|
+
avatar = bytes;
|
|
301
|
+
}
|
|
302
|
+
// Key/value fields on the plain PushDrop template; this action owns
|
|
303
|
+
// the layout.
|
|
304
|
+
const fields = [
|
|
305
|
+
Utils.toArray(IDENTITY_FIELD, 'utf8'),
|
|
306
|
+
Utils.toArray(identityKey, 'hex'),
|
|
307
|
+
Utils.toArray(PROFILE_FIELD, 'utf8'),
|
|
308
|
+
encodeProfile({
|
|
309
|
+
domain: input.profile?.domain ?? '',
|
|
310
|
+
name: input.profile?.name,
|
|
311
|
+
avatar,
|
|
312
|
+
}),
|
|
313
|
+
];
|
|
254
314
|
// Complete script, signature field zeroed — apply swaps in the real
|
|
255
315
|
// signature, so the size here is the size on chain.
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
], P1SAT_PROTOCOL, keyID, OPNS_REGISTER_COUNTERPARTY, true, false);
|
|
316
|
+
const pushDropLock = await new PushDrop(ctx.wallet).lock([...fields, new Array(OPNS_REGISTER_SIG_PLACEHOLDER_LEN).fill(0)], P1SAT_PROTOCOL, keyID, OPNS_REGISTER_COUNTERPARTY, true, false);
|
|
317
|
+
const unsealedLock = input.inscription
|
|
318
|
+
? Inscription.create(Uint8Array.from(input.inscription.content), input.inscription.contentType, { scriptPrefix: pushDropLock }).lock()
|
|
319
|
+
: pushDropLock;
|
|
261
320
|
const name = nameFromOutput(output);
|
|
262
321
|
const tags = opnsFileTags(output, [OPNS_PUBLISHED_TAG]);
|
|
263
322
|
const inputId = readAssetIdTag(output.tags);
|