@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,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BRC-78 portable encrypted message, with the crypto done by the wallet.
|
|
3
|
+
*
|
|
4
|
+
* BRC-78 is BRC-2 encryption under protocol `[2, 'message encryption']` with a
|
|
5
|
+
* random 32-byte key ID (base64 in the invoice number) and counterparty = the
|
|
6
|
+
* recipient: exactly BRC-100 `wallet.encrypt`. This module only writes the
|
|
7
|
+
* BRC-78 framing around the wallet's ciphertext, in the byte layout of
|
|
8
|
+
* `@bsv/sdk`'s `EncryptedMessage` (so its `decrypt` reads it):
|
|
9
|
+
*
|
|
10
|
+
* version `42421033` (4) ‖ sender identity key (33) ‖ recipient identity
|
|
11
|
+
* key (33) ‖ key ID (32) ‖ AES-256-GCM ciphertext (IV prepended)
|
|
12
|
+
*/
|
|
13
|
+
import { Utils } from '@bsv/sdk';
|
|
14
|
+
/** BRC-78 protocol, security level 2 */
|
|
15
|
+
export const BRC78_PROTOCOL = [2, 'message encryption'];
|
|
16
|
+
/** Version bytes, in `@bsv/sdk` `EncryptedMessage` order */
|
|
17
|
+
export const BRC78_VERSION = '42421033';
|
|
18
|
+
/**
|
|
19
|
+
* Encrypt `plaintext` to `recipient` (identity key hex) and return the BRC-78
|
|
20
|
+
* serialization.
|
|
21
|
+
*/
|
|
22
|
+
export async function encryptBrc78(wallet, plaintext, recipient) {
|
|
23
|
+
const keyID = Array.from(crypto.getRandomValues(new Uint8Array(32)));
|
|
24
|
+
const { ciphertext } = await wallet.encrypt({
|
|
25
|
+
plaintext,
|
|
26
|
+
protocolID: BRC78_PROTOCOL,
|
|
27
|
+
keyID: Utils.toBase64(keyID),
|
|
28
|
+
counterparty: recipient,
|
|
29
|
+
});
|
|
30
|
+
const { publicKey: sender } = await wallet.getPublicKey({
|
|
31
|
+
identityKey: true,
|
|
32
|
+
});
|
|
33
|
+
return [
|
|
34
|
+
...Utils.toArray(BRC78_VERSION, 'hex'),
|
|
35
|
+
...Utils.toArray(sender, 'hex'),
|
|
36
|
+
...Utils.toArray(recipient, 'hex'),
|
|
37
|
+
...keyID,
|
|
38
|
+
...ciphertext,
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Decrypt a BRC-78 serialization addressed to this wallet: the inverse of
|
|
43
|
+
* {@link encryptBrc78}. The key ID is read from the BRC-78 header; the
|
|
44
|
+
* counterparty is the sender's identity key.
|
|
45
|
+
*/
|
|
46
|
+
export async function decryptBrc78(wallet, message, sender) {
|
|
47
|
+
const bytes = Array.from(message);
|
|
48
|
+
if (Utils.toHex(bytes.slice(0, 4)) !== BRC78_VERSION) {
|
|
49
|
+
throw new Error('BRC-78: unsupported version');
|
|
50
|
+
}
|
|
51
|
+
const keyID = bytes.slice(4 + 33 + 33, 4 + 33 + 33 + 32);
|
|
52
|
+
const { plaintext } = await wallet.decrypt({
|
|
53
|
+
ciphertext: bytes.slice(4 + 33 + 33 + 32),
|
|
54
|
+
protocolID: BRC78_PROTOCOL,
|
|
55
|
+
keyID: Utils.toBase64(keyID),
|
|
56
|
+
counterparty: sender,
|
|
57
|
+
});
|
|
58
|
+
return plaintext;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=brc78.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"brc78.js","sourceRoot":"","sources":["../../src/metanet/brc78.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAE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,aAAa,EAAE,CAAC;QACtD,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;IAC/C,CAAC;IACD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAA;IACxD,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC1C,UAAU,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;QACzC,UAAU,EAAE,cAAc;QAC1B,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;QAC5B,YAAY,EAAE,MAAM;KACpB,CAAC,CAAA;IACF,OAAO,SAAS,CAAA;AACjB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Send a signed BRC-169 §7.3 envelope (DAG-CBOR, BRC-231 body over BRC-104)
|
|
3
|
+
* to a resolved handle's messagebox.
|
|
4
|
+
*
|
|
5
|
+
* `content` is BRC-78 encryption (via `wallet.encrypt`) of the given MIME
|
|
6
|
+
* plaintext to the recipient's identity key; `contentHash` is the SHA-256 of
|
|
7
|
+
* that plaintext; the signature is per §7.2 item 3.
|
|
8
|
+
*/
|
|
9
|
+
import type { HandleResolution } from '@1sat/client';
|
|
10
|
+
import { type WalletInterface } from '@bsv/sdk';
|
|
11
|
+
import { type EnvelopePayment } from './envelope.js';
|
|
12
|
+
/** A fresh random 16-byte value, base64: a BRC-29 derivation prefix/suffix or key ID half. */
|
|
13
|
+
export declare function randomBase64(): string;
|
|
14
|
+
export declare function sendEnvelope(wallet: WalletInterface, resolution: HandleResolution, p: {
|
|
15
|
+
/** Our identity key, hex */
|
|
16
|
+
senderIdentityKey: string;
|
|
17
|
+
/** The MIME entity `content` encrypts */
|
|
18
|
+
plaintext: number[];
|
|
19
|
+
payment: EnvelopePayment | null;
|
|
20
|
+
/** Messagebox box name */
|
|
21
|
+
messageBox: string;
|
|
22
|
+
}): Promise<{
|
|
23
|
+
status: string;
|
|
24
|
+
messageId: string;
|
|
25
|
+
}>;
|
|
26
|
+
//# sourceMappingURL=deliver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deliver.d.ts","sourceRoot":"","sources":["../../src/metanet/deliver.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,EAAe,KAAK,eAAe,EAAE,MAAM,UAAU,CAAA;AAE5D,OAAO,EAAE,KAAK,eAAe,EAAgB,MAAM,eAAe,CAAA;AAGlE,8FAA8F;AAC9F,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED,wBAAsB,YAAY,CACjC,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE,gBAAgB,EAC5B,CAAC,EAAE;IACF,4BAA4B;IAC5B,iBAAiB,EAAE,MAAM,CAAA;IACzB,yCAAyC;IACzC,SAAS,EAAE,MAAM,EAAE,CAAA;IACnB,OAAO,EAAE,eAAe,GAAG,IAAI,CAAA;IAC/B,0BAA0B;IAC1B,UAAU,EAAE,MAAM,CAAA;CAClB,GACC,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CA8BhD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Send a signed BRC-169 §7.3 envelope (DAG-CBOR, BRC-231 body over BRC-104)
|
|
3
|
+
* to a resolved handle's messagebox.
|
|
4
|
+
*
|
|
5
|
+
* `content` is BRC-78 encryption (via `wallet.encrypt`) of the given MIME
|
|
6
|
+
* plaintext to the recipient's identity key; `contentHash` is the SHA-256 of
|
|
7
|
+
* that plaintext; the signature is per §7.2 item 3.
|
|
8
|
+
*/
|
|
9
|
+
import { Hash, Utils } from '@bsv/sdk';
|
|
10
|
+
import { encryptBrc78 } from './brc78.js';
|
|
11
|
+
import { signEnvelope } from './envelope.js';
|
|
12
|
+
import { messageRelay } from './relay.js';
|
|
13
|
+
/** A fresh random 16-byte value, base64: a BRC-29 derivation prefix/suffix or key ID half. */
|
|
14
|
+
export function randomBase64() {
|
|
15
|
+
return Utils.toBase64(Array.from(crypto.getRandomValues(new Uint8Array(16))));
|
|
16
|
+
}
|
|
17
|
+
export async function sendEnvelope(wallet, resolution, p) {
|
|
18
|
+
const content = await encryptBrc78(wallet, p.plaintext, resolution.identityKey);
|
|
19
|
+
const bytes = (a) => Uint8Array.from(a);
|
|
20
|
+
const { envelope } = await signEnvelope(wallet, {
|
|
21
|
+
metanetHandles: '1.0',
|
|
22
|
+
recipient: {
|
|
23
|
+
handle: resolution.handle,
|
|
24
|
+
tag: resolution.tag,
|
|
25
|
+
domain: resolution.domain,
|
|
26
|
+
},
|
|
27
|
+
sender: { identityKey: bytes(Utils.toArray(p.senderIdentityKey, 'hex')) },
|
|
28
|
+
created: new Date().toISOString().replace(/\.\d{3}Z$/, 'Z'),
|
|
29
|
+
payment: p.payment,
|
|
30
|
+
contentHash: bytes(Hash.sha256(p.plaintext)),
|
|
31
|
+
}, bytes(content));
|
|
32
|
+
return messageRelay.sendCborMessage(wallet, resolution.messagebox, resolution.identityKey, p.messageBox, envelope);
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=deliver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deliver.js","sourceRoot":"","sources":["../../src/metanet/deliver.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,IAAI,EAAE,KAAK,EAAwB,MAAM,UAAU,CAAA;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAwB,YAAY,EAAE,MAAM,eAAe,CAAA;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,YAA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
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BRC-169 envelope, DAG-CBOR encoding (§7.2, §7.3).
|
|
3
|
+
*
|
|
4
|
+
* The signature is made by the key derived from `sender.identityKey` under
|
|
5
|
+
* protocol `[2, 'metanet handles envelope']`, key ID `send`, counterparty
|
|
6
|
+
* `anyone`, over SHA-256 of the DAG-CBOR map with `content` and `signature`
|
|
7
|
+
* removed. A verifier derives the same public key from `sender.identityKey`.
|
|
8
|
+
*/
|
|
9
|
+
import { type WalletInterface, type WalletProtocol } from '@bsv/sdk';
|
|
10
|
+
/** §7.2 item 3 signing protocol */
|
|
11
|
+
export declare const ENVELOPE_SIGNATURE_PROTOCOL: WalletProtocol;
|
|
12
|
+
/** §7.2 item 3 signing key ID */
|
|
13
|
+
export declare const ENVELOPE_SIGNATURE_KEY_ID = "send";
|
|
14
|
+
/** §7.3 `payment` member */
|
|
15
|
+
export interface EnvelopePayment {
|
|
16
|
+
derivationPrefix: Uint8Array;
|
|
17
|
+
derivationSuffix: Uint8Array;
|
|
18
|
+
/** UTF-8 bytes of the BRC-43 protocol name */
|
|
19
|
+
protocol: Uint8Array;
|
|
20
|
+
satoshis: number;
|
|
21
|
+
/** Atomic BEEF */
|
|
22
|
+
beef: Uint8Array;
|
|
23
|
+
}
|
|
24
|
+
/** The §7.3 envelope without `content` and `signature`: the signing preimage map. */
|
|
25
|
+
export interface UnsignedEnvelope {
|
|
26
|
+
metanetHandles: string;
|
|
27
|
+
recipient: {
|
|
28
|
+
handle: string;
|
|
29
|
+
tag?: string;
|
|
30
|
+
domain: string;
|
|
31
|
+
};
|
|
32
|
+
/** `identityKey` is the 33-byte compressed key */
|
|
33
|
+
sender: {
|
|
34
|
+
identityKey: Uint8Array;
|
|
35
|
+
handle?: string;
|
|
36
|
+
domain?: string;
|
|
37
|
+
};
|
|
38
|
+
/** ISO-8601 UTC timestamp */
|
|
39
|
+
created: string;
|
|
40
|
+
quoteId?: string;
|
|
41
|
+
payment: EnvelopePayment | null;
|
|
42
|
+
contentHash?: Uint8Array;
|
|
43
|
+
}
|
|
44
|
+
/** DAG-CBOR bytes of the envelope with `content` and `signature` removed. */
|
|
45
|
+
export declare function envelopeSigningPreimage(env: UnsignedEnvelope): Uint8Array;
|
|
46
|
+
/**
|
|
47
|
+
* Sign an envelope with the wallet's identity (§7.2 item 3) and return the
|
|
48
|
+
* full DAG-CBOR envelope, `content` and `signature` included.
|
|
49
|
+
*
|
|
50
|
+
* @param content - the encrypted content bytes (§7.3 `content`)
|
|
51
|
+
*/
|
|
52
|
+
export declare function signEnvelope(wallet: Pick<WalletInterface, 'createSignature'>, env: UnsignedEnvelope, content: Uint8Array): Promise<{
|
|
53
|
+
envelope: Uint8Array;
|
|
54
|
+
signature: Uint8Array;
|
|
55
|
+
}>;
|
|
56
|
+
/** A received §7.3 envelope: the signed members plus `content` and `signature`. */
|
|
57
|
+
export interface ReceivedEnvelope extends UnsignedEnvelope {
|
|
58
|
+
content: Uint8Array;
|
|
59
|
+
signature: Uint8Array;
|
|
60
|
+
}
|
|
61
|
+
/** Decode a §7.3 DAG-CBOR envelope. */
|
|
62
|
+
export declare function decodeEnvelope(bytes: Uint8Array): ReceivedEnvelope;
|
|
63
|
+
/**
|
|
64
|
+
* Verify an envelope's §7.2 item 3 signature: the key derived from
|
|
65
|
+
* `sender.identityKey` under the signing protocol, key ID `send`,
|
|
66
|
+
* counterparty `anyone`, over the map without `content` and `signature`.
|
|
67
|
+
*/
|
|
68
|
+
export declare function verifyEnvelope(env: ReceivedEnvelope): Promise<boolean>;
|
|
69
|
+
//# sourceMappingURL=envelope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../src/metanet/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAGN,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,MAAM,UAAU,CAAA;AAMjB,mCAAmC;AACn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AO,EAAE,UAAU,CAAA;IACnB,SAAS,EAAE,UAAU,CAAA;CACrB;AAED,uCAAuC;AACvC,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,gBAAgB,CAYlE;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAe5E"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BRC-169 envelope, DAG-CBOR encoding (§7.2, §7.3).
|
|
3
|
+
*
|
|
4
|
+
* The signature is made by the key derived from `sender.identityKey` under
|
|
5
|
+
* protocol `[2, 'metanet handles envelope']`, key ID `send`, counterparty
|
|
6
|
+
* `anyone`, over SHA-256 of the DAG-CBOR map with `content` and `signature`
|
|
7
|
+
* removed. A verifier derives the same public key from `sender.identityKey`.
|
|
8
|
+
*/
|
|
9
|
+
import { ProtoWallet, Utils, } from '@bsv/sdk';
|
|
10
|
+
import { decode as dagCborDecode, encode as dagCborEncode, } from '@ipld/dag-cbor';
|
|
11
|
+
/** §7.2 item 3 signing protocol */
|
|
12
|
+
export const ENVELOPE_SIGNATURE_PROTOCOL = [
|
|
13
|
+
2,
|
|
14
|
+
'metanet handles envelope',
|
|
15
|
+
];
|
|
16
|
+
/** §7.2 item 3 signing key ID */
|
|
17
|
+
export const ENVELOPE_SIGNATURE_KEY_ID = 'send';
|
|
18
|
+
/** Drop undefined members: DAG-CBOR has no `undefined`. */
|
|
19
|
+
function defined(obj) {
|
|
20
|
+
return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== undefined));
|
|
21
|
+
}
|
|
22
|
+
function envelopeMap(env) {
|
|
23
|
+
return defined({
|
|
24
|
+
...env,
|
|
25
|
+
recipient: defined(env.recipient),
|
|
26
|
+
sender: defined(env.sender),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/** DAG-CBOR bytes of the envelope with `content` and `signature` removed. */
|
|
30
|
+
export function envelopeSigningPreimage(env) {
|
|
31
|
+
return dagCborEncode(envelopeMap(env));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Sign an envelope with the wallet's identity (§7.2 item 3) and return the
|
|
35
|
+
* full DAG-CBOR envelope, `content` and `signature` included.
|
|
36
|
+
*
|
|
37
|
+
* @param content - the encrypted content bytes (§7.3 `content`)
|
|
38
|
+
*/
|
|
39
|
+
export async function signEnvelope(wallet, env, content) {
|
|
40
|
+
const { signature } = await wallet.createSignature({
|
|
41
|
+
data: Array.from(envelopeSigningPreimage(env)),
|
|
42
|
+
protocolID: ENVELOPE_SIGNATURE_PROTOCOL,
|
|
43
|
+
keyID: ENVELOPE_SIGNATURE_KEY_ID,
|
|
44
|
+
counterparty: 'anyone',
|
|
45
|
+
});
|
|
46
|
+
const sig = Uint8Array.from(signature);
|
|
47
|
+
return {
|
|
48
|
+
envelope: dagCborEncode({ ...envelopeMap(env), content, signature: sig }),
|
|
49
|
+
signature: sig,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** Decode a §7.3 DAG-CBOR envelope. */
|
|
53
|
+
export function decodeEnvelope(bytes) {
|
|
54
|
+
const env = dagCborDecode(bytes);
|
|
55
|
+
if (!env ||
|
|
56
|
+
typeof env !== 'object' ||
|
|
57
|
+
!(env.sender?.identityKey instanceof Uint8Array) ||
|
|
58
|
+
!(env.content instanceof Uint8Array) ||
|
|
59
|
+
!(env.signature instanceof Uint8Array)) {
|
|
60
|
+
throw new Error('not a BRC-169 DAG-CBOR envelope');
|
|
61
|
+
}
|
|
62
|
+
return env;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Verify an envelope's §7.2 item 3 signature: the key derived from
|
|
66
|
+
* `sender.identityKey` under the signing protocol, key ID `send`,
|
|
67
|
+
* counterparty `anyone`, over the map without `content` and `signature`.
|
|
68
|
+
*/
|
|
69
|
+
export async function verifyEnvelope(env) {
|
|
70
|
+
const { content: _c, signature, ...unsigned } = env;
|
|
71
|
+
try {
|
|
72
|
+
const { valid } = await new ProtoWallet('anyone').verifySignature({
|
|
73
|
+
data: Array.from(envelopeSigningPreimage(unsigned)),
|
|
74
|
+
signature: Array.from(signature),
|
|
75
|
+
protocolID: ENVELOPE_SIGNATURE_PROTOCOL,
|
|
76
|
+
keyID: ENVELOPE_SIGNATURE_KEY_ID,
|
|
77
|
+
counterparty: Utils.toHex(Array.from(env.sender.identityKey)),
|
|
78
|
+
});
|
|
79
|
+
return valid;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// ProtoWallet throws on an invalid signature.
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=envelope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../src/metanet/envelope.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACN,WAAW,EACX,KAAK,GAGL,MAAM,UAAU,CAAA;AACjB,OAAO,EACN,MAAM,IAAI,aAAa,EACvB,MAAM,IAAI,aAAa,GACvB,MAAM,gBAAgB,CAAA;AAEvB,mCAAmC;AACnC,MAAM,CAAC,MAAM,2BAA2B,GAAmB;IAC1D,CAAC;IACD,0BAA0B;CAC1B,CAAA;AACD,iCAAiC;AACjC,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAA;AA0B/C,2DAA2D;AAC3D,SAAS,OAAO,CAAmB,GAAM;IACxC,OAAO,MAAM,CAAC,WAAW,CACxB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CACjD,CAAA;AACP,CAAC;AAED,SAAS,WAAW,CAAC,GAAqB;IACzC,OAAO,OAAO,CAAC;QACd,GAAG,GAAG;QACN,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;QACjC,MAAM,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AM,CAAC,KAAK,UAAU,cAAc,CAAC,GAAqB;IACzD,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,QAAQ,EAAE,GAAG,GAAG,CAAA;IACnD,IAAI,CAAC;QACJ,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAC,eAAe,CAAC;YACjE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC;YACnD,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;YAChC,UAAU,EAAE,2BAA2B;YACvC,KAAK,EAAE,yBAAyB;YAChC,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;SAC7D,CAAC,CAAA;QACF,OAAO,KAAK,CAAA;IACb,CAAC;IAAC,MAAM,CAAC;QACR,8CAA8C;QAC9C,OAAO,KAAK,CAAA;IACb,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.test.d.ts","sourceRoot":"","sources":["../../src/metanet/envelope.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { PrivateKey, ProtoWallet, Utils } from '@bsv/sdk';
|
|
3
|
+
import { decode as dagCborDecode, encode as dagCborEncode, } from '@ipld/dag-cbor';
|
|
4
|
+
import { ENVELOPE_SIGNATURE_KEY_ID, ENVELOPE_SIGNATURE_PROTOCOL, envelopeSigningPreimage, signEnvelope, } from './envelope.js';
|
|
5
|
+
// BRC-169 Appendix A.7 (crumbs → deggen), binary form with an empty beef.
|
|
6
|
+
const CRUMBS_PRIV = 'cf94a849be462a110807900e45a909515c38a2d17b9a8e9753c9475bfd220848';
|
|
7
|
+
const CRUMBS_PUB = '0375b162a37d8794cfdcf72938d9467931e8586885b93c0da97051ecb512f46646';
|
|
8
|
+
const A7_PREIMAGE = 'a76673656e646572a366646f6d61696e6d6e657875732e6578616d706c656668616e646c65666372756d62736b6964656e746974794b657958210375b162a37d8794cfdcf72938d9467931e8586885b93c0da97051ecb512f46646676372656174656474323032362d30372d33305430393a31353a30305a677061796d656e74a56462656566406870726f746f636f6c6c333234313634353136316438687361746f736869731954297064657269766174696f6e507265666978500f5bcc8d7c345d512595d55982b5a4e37064657269766174696f6e537566666978509c42b65554891520ae960a7fb477759e6771756f746549647820306433346362333963316336666530366364346133343638363765316533333469726563697069656e74a36374616768636f6e663230333666646f6d61696e686c6b75702e6e65746668616e646c656664656767656e6b636f6e74656e7448617368582076f88073e3498f542c57fb9a2133743d6f0c1f9c4632e786116568ccd393e35c6e6d6574616e657448616e646c657363312e30';
|
|
9
|
+
const A7_SIGNATURE = '304402206a2bf0b0628386870202789d718001580279cc1add7b3dc3ff81e08858e22f8c022051d6e6d5756bf2bd1d06ea5199af080e721bb1f5dddefe9a36884796d5d04cf7';
|
|
10
|
+
const bytes = (hex) => Uint8Array.from(Utils.toArray(hex, 'hex'));
|
|
11
|
+
const utf8 = (s) => Uint8Array.from(Utils.toArray(s, 'utf8'));
|
|
12
|
+
const b64 = (s) => Uint8Array.from(Utils.toArray(s, 'base64'));
|
|
13
|
+
const A7 = {
|
|
14
|
+
metanetHandles: '1.0',
|
|
15
|
+
recipient: { handle: 'deggen', tag: 'conf2036', domain: 'lkup.net' },
|
|
16
|
+
sender: {
|
|
17
|
+
identityKey: bytes(CRUMBS_PUB),
|
|
18
|
+
handle: 'crumbs',
|
|
19
|
+
domain: 'nexus.example',
|
|
20
|
+
},
|
|
21
|
+
created: '2026-07-30T09:15:00Z',
|
|
22
|
+
quoteId: '0d34cb39c1c6fe06cd4a346867e1e334',
|
|
23
|
+
payment: {
|
|
24
|
+
derivationPrefix: b64('D1vMjXw0XVElldVZgrWk4w=='),
|
|
25
|
+
derivationSuffix: b64('nEK2VVSJFSCulgp/tHd1ng=='),
|
|
26
|
+
protocol: utf8('3241645161d8'),
|
|
27
|
+
satoshis: 21545,
|
|
28
|
+
beef: new Uint8Array(0),
|
|
29
|
+
},
|
|
30
|
+
contentHash: bytes('76f88073e3498f542c57fb9a2133743d6f0c1f9c4632e786116568ccd393e35c'),
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* BRC-169 §7.3 types `payment.protocol` as bstr, but the Appendix A.7 binary
|
|
34
|
+
* vector encodes it as tstr (`6c` + 12 bytes, not `4c`). This module follows
|
|
35
|
+
* the §7.3 table. To check every other member against A.7, the vector is
|
|
36
|
+
* rebuilt here with the appendix's tstr protocol.
|
|
37
|
+
*/
|
|
38
|
+
const A7_AS_PRINTED = {
|
|
39
|
+
...A7,
|
|
40
|
+
payment: { ...A7.payment, protocol: '3241645161d8' },
|
|
41
|
+
};
|
|
42
|
+
describe('BRC-169 envelope (DAG-CBOR)', () => {
|
|
43
|
+
test('signing preimage matches Appendix A.7 byte for byte (tstr protocol as printed)', () => {
|
|
44
|
+
expect(Utils.toHex(Array.from(envelopeSigningPreimage(A7_AS_PRINTED)))).toBe(A7_PREIMAGE);
|
|
45
|
+
});
|
|
46
|
+
test('payment.protocol is encoded as bstr per the §7.3 table', () => {
|
|
47
|
+
const hex = Utils.toHex(Array.from(envelopeSigningPreimage(A7)));
|
|
48
|
+
// 0x4c = bstr(12); the appendix prints 0x6c = tstr(12)
|
|
49
|
+
expect(hex).toContain('6870726f746f636f6c4c333234313634353136316438');
|
|
50
|
+
expect(hex).toBe(A7_PREIMAGE.replace('6870726f746f636f6c6c', '6870726f746f636f6c4c'));
|
|
51
|
+
});
|
|
52
|
+
test('the Appendix A.7 signature verifies under the §7.2 derivation', async () => {
|
|
53
|
+
const { valid } = await new ProtoWallet('anyone').verifySignature({
|
|
54
|
+
data: Array.from(envelopeSigningPreimage(A7_AS_PRINTED)),
|
|
55
|
+
signature: Utils.toArray(A7_SIGNATURE, 'hex'),
|
|
56
|
+
protocolID: ENVELOPE_SIGNATURE_PROTOCOL,
|
|
57
|
+
keyID: ENVELOPE_SIGNATURE_KEY_ID,
|
|
58
|
+
counterparty: CRUMBS_PUB,
|
|
59
|
+
});
|
|
60
|
+
expect(valid).toBe(true);
|
|
61
|
+
});
|
|
62
|
+
test('envelope bytes are canonical DAG-CBOR and carry content + signature', async () => {
|
|
63
|
+
const wallet = new ProtoWallet(PrivateKey.fromHex(CRUMBS_PRIV));
|
|
64
|
+
const content = utf8('opaque content');
|
|
65
|
+
const { envelope, signature } = await signEnvelope(wallet, A7_AS_PRINTED, content);
|
|
66
|
+
const decoded = dagCborDecode(envelope);
|
|
67
|
+
expect(dagCborEncode(decoded)).toEqual(envelope);
|
|
68
|
+
expect(decoded.content).toEqual(content);
|
|
69
|
+
expect(decoded.signature).toEqual(signature);
|
|
70
|
+
const { content: _c, signature: _s, ...rest } = decoded;
|
|
71
|
+
expect(Utils.toHex(Array.from(dagCborEncode(rest)))).toBe(A7_PREIMAGE);
|
|
72
|
+
});
|
|
73
|
+
test('signature verifies from sender.identityKey with the §7.2 derivation', async () => {
|
|
74
|
+
const wallet = new ProtoWallet(PrivateKey.fromHex(CRUMBS_PRIV));
|
|
75
|
+
const unsigned = {
|
|
76
|
+
metanetHandles: '1.0',
|
|
77
|
+
recipient: { handle: 'deggen', domain: 'lkup.net' },
|
|
78
|
+
sender: { identityKey: bytes(CRUMBS_PUB) },
|
|
79
|
+
created: '2026-10-03T00:00:00Z',
|
|
80
|
+
payment: {
|
|
81
|
+
derivationPrefix: new Uint8Array(16).fill(1),
|
|
82
|
+
derivationSuffix: new Uint8Array(16).fill(2),
|
|
83
|
+
protocol: utf8('mandala'),
|
|
84
|
+
satoshis: 1,
|
|
85
|
+
beef: new Uint8Array([1, 2, 3]),
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
const { envelope } = await signEnvelope(wallet, unsigned, utf8('x'));
|
|
89
|
+
// A verifier re-encodes the received map without content/signature.
|
|
90
|
+
const received = dagCborDecode(envelope);
|
|
91
|
+
const { content: _c, signature, ...rest } = received;
|
|
92
|
+
const sender = rest.sender.identityKey;
|
|
93
|
+
const preimage = envelopeSigningPreimage(rest);
|
|
94
|
+
expect(preimage).toEqual(envelopeSigningPreimage(unsigned));
|
|
95
|
+
const verifier = new ProtoWallet('anyone');
|
|
96
|
+
const { valid } = await verifier.verifySignature({
|
|
97
|
+
data: Array.from(preimage),
|
|
98
|
+
signature: Array.from(signature),
|
|
99
|
+
protocolID: ENVELOPE_SIGNATURE_PROTOCOL,
|
|
100
|
+
keyID: ENVELOPE_SIGNATURE_KEY_ID,
|
|
101
|
+
counterparty: Utils.toHex(Array.from(sender)),
|
|
102
|
+
});
|
|
103
|
+
expect(valid).toBe(true);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
//# sourceMappingURL=envelope.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.test.js","sourceRoot":"","sources":["../../src/metanet/envelope.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AACzD,OAAO,EACN,MAAM,IAAI,aAAa,EACvB,MAAM,IAAI,aAAa,GACvB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACN,yBAAyB,EACzB,2BAA2B,EAE3B,uBAAuB,EACvB,YAAY,GACZ,MAAM,eAAe,CAAA;AAEtB,0EAA0E;AAC1E,MAAM,WAAW,GAChB,kEAAkE,CAAA;AACnE,MAAM,UAAU,GACf,oEAAoE,CAAA;AACrE,MAAM,WAAW,GAChB,8xBAA8xB,CAAA;AAC/xB,MAAM,YAAY,GACjB,8IAA8I,CAAA;AAE/I,MAAM,KAAK,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CA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RC-104), decode each §7.3
|
|
4
|
+
* DAG-CBOR envelope, verify its §7.2 signature against `sender.identityKey`,
|
|
5
|
+
* decrypt the BRC-78 `content` with `wallet.decrypt`, check `contentHash`,
|
|
6
|
+
* parse the MIME entity, hand it to the box's handler, and acknowledge only
|
|
7
|
+
* the messages whose handler succeeded. A message whose handler throws is
|
|
8
|
+
* left in the box and reported with the reason.
|
|
9
|
+
*/
|
|
10
|
+
import { type MimeEntity } from '@1sat/utils';
|
|
11
|
+
import { type WalletInterface } from '@bsv/sdk';
|
|
12
|
+
import { type ReceivedEnvelope } from './envelope.js';
|
|
13
|
+
import { type CborMessage } from './relay.js';
|
|
14
|
+
/** Default messagebox when the caller names none. */
|
|
15
|
+
export declare const DEFAULT_MESSAGEBOX_URL = "https://messagebox.1sat.app";
|
|
16
|
+
/** A message left in the box, and why. */
|
|
17
|
+
export interface InboxSkip {
|
|
18
|
+
messageId: string;
|
|
19
|
+
reason: string;
|
|
20
|
+
}
|
|
21
|
+
/** Thrown to leave a message unacknowledged with a reason. */
|
|
22
|
+
export declare class InboxSkipError extends Error {
|
|
23
|
+
}
|
|
24
|
+
/** Hex of a byte string of the given length, or InboxSkipError. */
|
|
25
|
+
export declare function bytesHex(b: unknown, length: number, what: string): string;
|
|
26
|
+
/** A verified, decrypted envelope. */
|
|
27
|
+
export interface OpenedEnvelope {
|
|
28
|
+
env: ReceivedEnvelope;
|
|
29
|
+
/** `sender.identityKey`, hex */
|
|
30
|
+
sender: string;
|
|
31
|
+
/** The decrypted `content` */
|
|
32
|
+
plaintext: number[];
|
|
33
|
+
entity: MimeEntity;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Decode, verify, decrypt and parse one envelope addressed to this wallet.
|
|
37
|
+
*
|
|
38
|
+
* @throws InboxSkipError when it is not a DAG-CBOR envelope, the signature
|
|
39
|
+
* does not verify, or `contentHash` does not match
|
|
40
|
+
*/
|
|
41
|
+
export declare function openEnvelope(wallet: Pick<WalletInterface, 'decrypt'>, body: Uint8Array): Promise<OpenedEnvelope>;
|
|
42
|
+
/**
|
|
43
|
+
* List `messageBox`, open each envelope and run `handle` on it; acknowledge
|
|
44
|
+
* the messages `handle` returned for.
|
|
45
|
+
*/
|
|
46
|
+
export declare function processInbox<R>(wallet: WalletInterface, messageboxUrl: string | undefined, messageBox: string, handle: (opened: OpenedEnvelope, msg: CborMessage) => Promise<R>): Promise<{
|
|
47
|
+
received: R[];
|
|
48
|
+
skipped: InboxSkip[];
|
|
49
|
+
error?: string;
|
|
50
|
+
}>;
|
|
51
|
+
//# sourceMappingURL=inbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inbox.d.ts","sourceRoot":"","sources":["../../src/metanet/inbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,UAAU,EAAmB,MAAM,aAAa,CAAA;AAC9D,OAAO,EAAe,KAAK,eAAe,EAAE,MAAM,UAAU,CAAA;AAE5D,OAAO,EACN,KAAK,gBAAgB,EAGrB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,KAAK,WAAW,EAAgB,MAAM,YAAY,CAAA;AAE3D,qDAAqD;AACrD,eAAO,MAAM,sBAAsB,gCAAgC,CAAA;AAEnE,0CAA0C;AAC1C,MAAM,WAAW,SAAS;IACzB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;CACd;AAED,8DAA8D;AAC9D,qBAAa,cAAe,SAAQ,KAAK;CAAG;AAE5C,mEAAmE;AACnE,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAKzE;AAED,sCAAsC;AACtC,MAAM,WAAW,cAAc;IAC9B,GAAG,EAAE,gBAAgB,CAAA;IACrB,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAA;IACd,8BAA8B;IAC9B,SAAS,EAAE,MAAM,EAAE,CAAA;IACnB,MAAM,EAAE,UAAU,CAAA;CAClB;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CACjC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,EACxC,IAAI,EAAE,UAAU,GACd,OAAO,CAAC,cAAc,CAAC,CAoBzB;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,CAAC,EACnC,MAAM,EAAE,eAAe,EACvB,aAAa,EAAE,MAAM,GAAG,SAAS,EACjC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GAC9D,OAAO,CAAC;IAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;IAAC,OAAO,EAAE,SAAS,EAAE,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAmDlE"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The messagebox steps shared by the BRC-169 inbox syncs (`mandala_inbox`,
|
|
3
|
+
* `metanet_inbox`): list a box (BRC-231 over BRC-104), decode each §7.3
|
|
4
|
+
* DAG-CBOR envelope, verify its §7.2 signature against `sender.identityKey`,
|
|
5
|
+
* decrypt the BRC-78 `content` with `wallet.decrypt`, check `contentHash`,
|
|
6
|
+
* parse the MIME entity, hand it to the box's handler, and acknowledge only
|
|
7
|
+
* the messages whose handler succeeded. A message whose handler throws is
|
|
8
|
+
* left in the box and reported with the reason.
|
|
9
|
+
*/
|
|
10
|
+
import { parseMimeEntity } from '@1sat/utils';
|
|
11
|
+
import { Hash, Utils } from '@bsv/sdk';
|
|
12
|
+
import { decryptBrc78 } from './brc78.js';
|
|
13
|
+
import { decodeEnvelope, verifyEnvelope, } from './envelope.js';
|
|
14
|
+
import { messageRelay } from './relay.js';
|
|
15
|
+
/** Default messagebox when the caller names none. */
|
|
16
|
+
export const DEFAULT_MESSAGEBOX_URL = 'https://messagebox.1sat.app';
|
|
17
|
+
/** Thrown to leave a message unacknowledged with a reason. */
|
|
18
|
+
export class InboxSkipError extends Error {
|
|
19
|
+
}
|
|
20
|
+
/** Hex of a byte string of the given length, or InboxSkipError. */
|
|
21
|
+
export function bytesHex(b, length, what) {
|
|
22
|
+
if (!(b instanceof Uint8Array) || b.length !== length) {
|
|
23
|
+
throw new InboxSkipError(`${what} must be ${length} bytes`);
|
|
24
|
+
}
|
|
25
|
+
return Utils.toHex(Array.from(b));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Decode, verify, decrypt and parse one envelope addressed to this wallet.
|
|
29
|
+
*
|
|
30
|
+
* @throws InboxSkipError when it is not a DAG-CBOR envelope, the signature
|
|
31
|
+
* does not verify, or `contentHash` does not match
|
|
32
|
+
*/
|
|
33
|
+
export async function openEnvelope(wallet, body) {
|
|
34
|
+
let env;
|
|
35
|
+
try {
|
|
36
|
+
env = decodeEnvelope(body);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
throw new InboxSkipError('not a DAG-CBOR BRC-169 envelope');
|
|
40
|
+
}
|
|
41
|
+
if (!(await verifyEnvelope(env))) {
|
|
42
|
+
throw new InboxSkipError('envelope signature does not verify');
|
|
43
|
+
}
|
|
44
|
+
const sender = bytesHex(env.sender.identityKey, 33, 'sender');
|
|
45
|
+
const plaintext = await decryptBrc78(wallet, env.content, sender);
|
|
46
|
+
if (env.contentHash !== undefined &&
|
|
47
|
+
Utils.toHex(Hash.sha256(plaintext)) !==
|
|
48
|
+
Utils.toHex(Array.from(env.contentHash))) {
|
|
49
|
+
throw new InboxSkipError('contentHash does not match the content');
|
|
50
|
+
}
|
|
51
|
+
return { env, sender, plaintext, entity: parseMimeEntity(plaintext) };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* List `messageBox`, open each envelope and run `handle` on it; acknowledge
|
|
55
|
+
* the messages `handle` returned for.
|
|
56
|
+
*/
|
|
57
|
+
export async function processInbox(wallet, messageboxUrl, messageBox, handle) {
|
|
58
|
+
const messagebox = messageboxUrl?.replace(/\/+$/, '') || DEFAULT_MESSAGEBOX_URL;
|
|
59
|
+
const received = [];
|
|
60
|
+
const skipped = [];
|
|
61
|
+
const acknowledged = [];
|
|
62
|
+
let messages;
|
|
63
|
+
try {
|
|
64
|
+
messages = await messageRelay.listCborMessages(wallet, messagebox, messageBox);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
return {
|
|
68
|
+
received,
|
|
69
|
+
skipped,
|
|
70
|
+
error: error instanceof Error ? error.message : String(error),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
for (const msg of messages) {
|
|
74
|
+
try {
|
|
75
|
+
const opened = await openEnvelope(wallet, msg.body);
|
|
76
|
+
received.push(await handle(opened, msg));
|
|
77
|
+
acknowledged.push(msg.messageId);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
skipped.push({
|
|
81
|
+
messageId: msg.messageId,
|
|
82
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (acknowledged.length > 0) {
|
|
87
|
+
try {
|
|
88
|
+
await messageRelay.acknowledgeCborMessages(wallet, messagebox, acknowledged);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
return {
|
|
92
|
+
received,
|
|
93
|
+
skipped,
|
|
94
|
+
error: `acknowledge-failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return { received, skipped };
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=inbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inbox.js","sourceRoot":"","sources":["../../src/metanet/inbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAmB,eAAe,EAAE,MAAM,aAAa,CAAA;AAC9D,OAAO,E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,IAAI,CAAC,CAAA;YACnD,QAAQ,CAAC,IAAI,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;YACxC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;QACjC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,CAAC,IAAI,CAAC;gBACZ,SAAS,EAAE,GAAG,CAAC,SAAS;gBACxB,MAAM,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAC9D,CAAC,CAAA;QACH,CAAC;IACF,CAAC;IAED,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7B,IAAI,CAAC;YACJ,MAAM,YAAY,CAAC,uBAAuB,CACzC,MAAM,EACN,UAAU,EACV,YAAY,CACZ,CAAA;QACF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO;gBACN,QAAQ;gBACR,OAAO;gBACP,KAAK,EAAE,uBAAuB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;aACtF,CAAA;QACF,CAAC;IACF,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAA;AAC7B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BRC-169 envelope plumbing shared by the handle-addressed actions (Mandala
|
|
3
|
+
* sends, `sendBsv` to a handle) and the `metanet_inbox` sync.
|
|
4
|
+
*/
|
|
5
|
+
export * from './envelope.js';
|
|
6
|
+
export * from './receive.js';
|
|
7
|
+
export declare const metanetActions: import("../types.js").Action<import("./receive.js").SyncMetanetInboxInput, import("./receive.js").SyncMetanetInboxResult>[];
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/metanet/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAE5B,eAAO,MAAM,cAAc,6HAAqB,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BRC-169 envelope plumbing shared by the handle-addressed actions (Mandala
|
|
3
|
+
* sends, `sendBsv` to a handle) and the `metanet_inbox` sync.
|
|
4
|
+
*/
|
|
5
|
+
import { syncMetanetInbox } from './receive.js';
|
|
6
|
+
export * from './envelope.js';
|
|
7
|
+
export * from './receive.js';
|
|
8
|
+
export const metanetActions = [syncMetanetInbox];
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/metanet/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAE/C,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAE5B,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,gBAAgB,CAAC,CAAA"}
|