@1sat/actions 0.0.56 → 0.0.58
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authToken.d.ts","sourceRoot":"","sources":["../../src/signing/authToken.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,UAAU,CAAA;AAOrD,MAAM,WAAW,gBAAgB;IAChC,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,
|
|
1
|
+
{"version":3,"file":"authToken.d.ts","sourceRoot":"","sources":["../../src/signing/authToken.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,UAAU,CAAA;AAOrD,MAAM,WAAW,gBAAgB;IAChC,WAAW,EAAE,MAAM,CAAA;IACnB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,YAAY,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAA;IACxC,SAAS,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,iBAAiB;IACjC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;CACd;AAED,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,gBAAgB,EAAE,iBAAiB,CA2EpE,CAAA"}
|
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const { toArray, toHex } = Utils;
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
function compactSign(derSig, msgHash, pubKeyHex) {
|
|
6
|
-
const sig = Signature.fromDER(toHex(derSig), 'hex');
|
|
7
|
-
const pubKey = PublicKey.fromString(pubKeyHex);
|
|
8
|
-
const recovery = sig.CalculateRecoveryFactor(pubKey, new BigNumber(msgHash));
|
|
9
|
-
return sig.toCompact(recovery, true, 'base64');
|
|
10
|
-
}
|
|
1
|
+
import { Hash, Random, Utils } from '@bsv/sdk';
|
|
2
|
+
const { toArray, toBase64, toHex } = Utils;
|
|
3
|
+
const BRC77_VERSION = [0x42, 0x42, 0x33, 0x01];
|
|
4
|
+
const BRC77_PROTOCOL_ID = [2, 'message signing'];
|
|
11
5
|
export const getAuthToken = {
|
|
12
6
|
meta: {
|
|
13
7
|
name: 'getAuthToken',
|
|
14
|
-
description: 'Generate a BRC-77
|
|
8
|
+
description: 'Generate a BRC-77 auth token for HTTP request signing',
|
|
15
9
|
category: 'signing',
|
|
16
10
|
inputSchema: {
|
|
17
11
|
type: 'object',
|
|
@@ -24,11 +18,6 @@ export const getAuthToken = {
|
|
|
24
18
|
type: 'string',
|
|
25
19
|
description: 'Request body to include in signature',
|
|
26
20
|
},
|
|
27
|
-
scheme: {
|
|
28
|
-
type: 'string',
|
|
29
|
-
enum: ['brc77', 'bsm'],
|
|
30
|
-
description: 'Signature scheme (default: brc77)',
|
|
31
|
-
},
|
|
32
21
|
bodyEncoding: {
|
|
33
22
|
type: 'string',
|
|
34
23
|
enum: ['utf8', 'hex', 'base64'],
|
|
@@ -44,7 +33,6 @@ export const getAuthToken = {
|
|
|
44
33
|
},
|
|
45
34
|
async execute(ctx, input) {
|
|
46
35
|
try {
|
|
47
|
-
const scheme = input.scheme ?? 'brc77';
|
|
48
36
|
const bodyEncoding = input.bodyEncoding ?? 'utf8';
|
|
49
37
|
const timestamp = input.timestamp ?? new Date().toISOString();
|
|
50
38
|
const bodyHash = input.body
|
|
@@ -52,22 +40,27 @@ export const getAuthToken = {
|
|
|
52
40
|
: '';
|
|
53
41
|
const message = `${input.requestPath}|${timestamp}|${bodyHash}`;
|
|
54
42
|
const messageBytes = toArray(message, 'utf8');
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
protocolID: AUTH_PROTOCOL_ID,
|
|
60
|
-
keyID: AUTH_KEY_ID,
|
|
61
|
-
forSelf: true,
|
|
43
|
+
const keyID = Random(32);
|
|
44
|
+
const keyIDBase64 = toBase64(keyID);
|
|
45
|
+
const { publicKey: senderPubKeyHex } = await ctx.wallet.getPublicKey({
|
|
46
|
+
identityKey: true,
|
|
62
47
|
});
|
|
63
48
|
const { signature: derSig } = await ctx.wallet.createSignature({
|
|
64
|
-
protocolID:
|
|
65
|
-
keyID:
|
|
66
|
-
counterparty: '
|
|
67
|
-
|
|
49
|
+
protocolID: BRC77_PROTOCOL_ID,
|
|
50
|
+
keyID: keyIDBase64,
|
|
51
|
+
counterparty: 'anyone',
|
|
52
|
+
data: Array.from(messageBytes),
|
|
68
53
|
});
|
|
69
|
-
const
|
|
70
|
-
const
|
|
54
|
+
const senderPubKeyBytes = toArray(senderPubKeyHex, 'hex');
|
|
55
|
+
const envelope = [
|
|
56
|
+
...BRC77_VERSION,
|
|
57
|
+
...senderPubKeyBytes,
|
|
58
|
+
0x00,
|
|
59
|
+
...keyID,
|
|
60
|
+
...derSig,
|
|
61
|
+
];
|
|
62
|
+
const signatureBase64 = toBase64(envelope);
|
|
63
|
+
const authToken = `${senderPubKeyHex}|brc77|${timestamp}|${input.requestPath}|${signatureBase64}`;
|
|
71
64
|
return { authToken };
|
|
72
65
|
}
|
|
73
66
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authToken.js","sourceRoot":"","sources":["../../src/signing/authToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"authToken.js","sourceRoot":"","sources":["../../src/signing/authToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAG9C,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,KAAK,CAAA;AAE1C,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;AAC9C,MAAM,iBAAiB,GAAwB,CAAC,CAAC,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at SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@1sat/client": "0.0.16",
|
|
25
25
|
"@1sat/types": "0.0.13",
|
|
26
26
|
"@1sat/utils": "0.0.11",
|
|
27
|
-
"@1sat/wallet": "0.0.
|
|
27
|
+
"@1sat/wallet": "0.0.31",
|
|
28
28
|
"@1sat/templates": "0.0.2"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|