@ubiquity-os/plugin-sdk 1.0.8 → 1.0.10
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/constants.cjs +58 -0
- package/dist/constants.d.cts +9 -0
- package/dist/constants.d.ts +9 -0
- package/dist/constants.js +26 -0
- package/dist/{index.mjs → index.cjs} +112 -80
- package/dist/index.d.cts +57 -0
- package/dist/index.d.ts +4 -23
- package/dist/index.js +73 -125
- package/dist/manifest.cjs +47 -0
- package/dist/{index.d.mts → manifest.d.cts} +7 -62
- package/dist/manifest.d.ts +21 -0
- package/dist/manifest.js +20 -0
- package/dist/signature.cjs +81 -0
- package/dist/signature.d.cts +12 -0
- package/dist/signature.d.ts +12 -0
- package/dist/signature.js +55 -0
- package/package.json +42 -8
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/signature.ts
|
|
21
|
+
var signature_exports = {};
|
|
22
|
+
__export(signature_exports, {
|
|
23
|
+
signPayload: () => signPayload,
|
|
24
|
+
verifySignature: () => verifySignature
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(signature_exports);
|
|
27
|
+
async function verifySignature(publicKeyPem, inputs, signature) {
|
|
28
|
+
try {
|
|
29
|
+
const inputsOrdered = {
|
|
30
|
+
stateId: inputs.stateId,
|
|
31
|
+
eventName: inputs.eventName,
|
|
32
|
+
eventPayload: inputs.eventPayload,
|
|
33
|
+
settings: inputs.settings,
|
|
34
|
+
authToken: inputs.authToken,
|
|
35
|
+
ref: inputs.ref
|
|
36
|
+
};
|
|
37
|
+
const pemContents = publicKeyPem.replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "").trim();
|
|
38
|
+
const binaryDer = Uint8Array.from(atob(pemContents), (c) => c.charCodeAt(0));
|
|
39
|
+
const publicKey = await crypto.subtle.importKey(
|
|
40
|
+
"spki",
|
|
41
|
+
binaryDer,
|
|
42
|
+
{
|
|
43
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
44
|
+
hash: "SHA-256"
|
|
45
|
+
},
|
|
46
|
+
true,
|
|
47
|
+
["verify"]
|
|
48
|
+
);
|
|
49
|
+
const signatureArray = Uint8Array.from(atob(signature), (c) => c.charCodeAt(0));
|
|
50
|
+
const dataArray = new TextEncoder().encode(JSON.stringify(inputsOrdered));
|
|
51
|
+
return await crypto.subtle.verify("RSASSA-PKCS1-v1_5", publicKey, signatureArray, dataArray);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error(error);
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async function importRsaPrivateKey(pem) {
|
|
58
|
+
const pemContents = pem.replace("-----BEGIN PRIVATE KEY-----", "").replace("-----END PRIVATE KEY-----", "").trim();
|
|
59
|
+
const binaryDer = Uint8Array.from(atob(pemContents), (c) => c.charCodeAt(0));
|
|
60
|
+
return await crypto.subtle.importKey(
|
|
61
|
+
"pkcs8",
|
|
62
|
+
binaryDer.buffer,
|
|
63
|
+
{
|
|
64
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
65
|
+
hash: "SHA-256"
|
|
66
|
+
},
|
|
67
|
+
true,
|
|
68
|
+
["sign"]
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
async function signPayload(payload, privateKey) {
|
|
72
|
+
const data = new TextEncoder().encode(payload);
|
|
73
|
+
const _privateKey = await importRsaPrivateKey(privateKey);
|
|
74
|
+
const signature = await crypto.subtle.sign("RSASSA-PKCS1-v1_5", _privateKey, data);
|
|
75
|
+
return btoa(String.fromCharCode(...new Uint8Array(signature)));
|
|
76
|
+
}
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
signPayload,
|
|
80
|
+
verifySignature
|
|
81
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface Inputs {
|
|
2
|
+
stateId: unknown;
|
|
3
|
+
eventName: unknown;
|
|
4
|
+
eventPayload: unknown;
|
|
5
|
+
authToken: unknown;
|
|
6
|
+
settings: unknown;
|
|
7
|
+
ref: unknown;
|
|
8
|
+
}
|
|
9
|
+
declare function verifySignature(publicKeyPem: string, inputs: Inputs, signature: string): Promise<boolean>;
|
|
10
|
+
declare function signPayload(payload: string, privateKey: string): Promise<string>;
|
|
11
|
+
|
|
12
|
+
export { signPayload, verifySignature };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface Inputs {
|
|
2
|
+
stateId: unknown;
|
|
3
|
+
eventName: unknown;
|
|
4
|
+
eventPayload: unknown;
|
|
5
|
+
authToken: unknown;
|
|
6
|
+
settings: unknown;
|
|
7
|
+
ref: unknown;
|
|
8
|
+
}
|
|
9
|
+
declare function verifySignature(publicKeyPem: string, inputs: Inputs, signature: string): Promise<boolean>;
|
|
10
|
+
declare function signPayload(payload: string, privateKey: string): Promise<string>;
|
|
11
|
+
|
|
12
|
+
export { signPayload, verifySignature };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// src/signature.ts
|
|
2
|
+
async function verifySignature(publicKeyPem, inputs, signature) {
|
|
3
|
+
try {
|
|
4
|
+
const inputsOrdered = {
|
|
5
|
+
stateId: inputs.stateId,
|
|
6
|
+
eventName: inputs.eventName,
|
|
7
|
+
eventPayload: inputs.eventPayload,
|
|
8
|
+
settings: inputs.settings,
|
|
9
|
+
authToken: inputs.authToken,
|
|
10
|
+
ref: inputs.ref
|
|
11
|
+
};
|
|
12
|
+
const pemContents = publicKeyPem.replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "").trim();
|
|
13
|
+
const binaryDer = Uint8Array.from(atob(pemContents), (c) => c.charCodeAt(0));
|
|
14
|
+
const publicKey = await crypto.subtle.importKey(
|
|
15
|
+
"spki",
|
|
16
|
+
binaryDer,
|
|
17
|
+
{
|
|
18
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
19
|
+
hash: "SHA-256"
|
|
20
|
+
},
|
|
21
|
+
true,
|
|
22
|
+
["verify"]
|
|
23
|
+
);
|
|
24
|
+
const signatureArray = Uint8Array.from(atob(signature), (c) => c.charCodeAt(0));
|
|
25
|
+
const dataArray = new TextEncoder().encode(JSON.stringify(inputsOrdered));
|
|
26
|
+
return await crypto.subtle.verify("RSASSA-PKCS1-v1_5", publicKey, signatureArray, dataArray);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error(error);
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function importRsaPrivateKey(pem) {
|
|
33
|
+
const pemContents = pem.replace("-----BEGIN PRIVATE KEY-----", "").replace("-----END PRIVATE KEY-----", "").trim();
|
|
34
|
+
const binaryDer = Uint8Array.from(atob(pemContents), (c) => c.charCodeAt(0));
|
|
35
|
+
return await crypto.subtle.importKey(
|
|
36
|
+
"pkcs8",
|
|
37
|
+
binaryDer.buffer,
|
|
38
|
+
{
|
|
39
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
40
|
+
hash: "SHA-256"
|
|
41
|
+
},
|
|
42
|
+
true,
|
|
43
|
+
["sign"]
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
async function signPayload(payload, privateKey) {
|
|
47
|
+
const data = new TextEncoder().encode(payload);
|
|
48
|
+
const _privateKey = await importRsaPrivateKey(privateKey);
|
|
49
|
+
const signature = await crypto.subtle.sign("RSASSA-PKCS1-v1_5", _privateKey, data);
|
|
50
|
+
return btoa(String.fromCharCode(...new Uint8Array(signature)));
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
signPayload,
|
|
54
|
+
verifySignature
|
|
55
|
+
};
|
package/package.json
CHANGED
|
@@ -1,20 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ubiquity-os/plugin-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "SDK for plugin support.",
|
|
5
5
|
"author": "Ubiquity DAO",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"engines": {
|
|
8
8
|
"node": ">=20.10.0"
|
|
9
9
|
},
|
|
10
|
+
"type": "module",
|
|
10
11
|
"module": "dist/index.mjs",
|
|
11
12
|
"main": "dist/index.js",
|
|
12
13
|
"typings": "dist/index.d.ts",
|
|
14
|
+
"types": "dist/index.d.ts",
|
|
15
|
+
"typesVersions": {
|
|
16
|
+
"*": {
|
|
17
|
+
"manifest": [
|
|
18
|
+
"dist/manifest.d.ts"
|
|
19
|
+
],
|
|
20
|
+
"constants": [
|
|
21
|
+
"dist/constants.d.ts"
|
|
22
|
+
],
|
|
23
|
+
"signature": [
|
|
24
|
+
"dist/signature.d.ts"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
13
28
|
"exports": {
|
|
14
29
|
".": {
|
|
15
30
|
"types": "./dist/index.d.ts",
|
|
16
31
|
"require": "./dist/index.js",
|
|
17
32
|
"import": "./dist/index.mjs"
|
|
33
|
+
},
|
|
34
|
+
"./manifest": {
|
|
35
|
+
"types": "./dist/manifest.d.ts",
|
|
36
|
+
"import": "./dist/manifest.mjs",
|
|
37
|
+
"require": "./dist/manifest.js"
|
|
38
|
+
},
|
|
39
|
+
"./constants": {
|
|
40
|
+
"types": "./dist/constants.d.ts",
|
|
41
|
+
"import": "./dist/constants.mjs",
|
|
42
|
+
"require": "./dist/constants.js"
|
|
43
|
+
},
|
|
44
|
+
"./signature": {
|
|
45
|
+
"types": "./dist/signature.d.ts",
|
|
46
|
+
"import": "./dist/signature.mjs",
|
|
47
|
+
"require": "./dist/signature.js"
|
|
18
48
|
}
|
|
19
49
|
},
|
|
20
50
|
"files": [
|
|
@@ -29,7 +59,7 @@
|
|
|
29
59
|
"knip": "knip --config .github/knip.ts",
|
|
30
60
|
"knip-ci": "knip --no-exit-code --reporter json --config .github/knip.ts",
|
|
31
61
|
"prepare": "node .husky/install.mjs",
|
|
32
|
-
"test": "jest --setupFiles dotenv/config --coverage"
|
|
62
|
+
"jest:test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --setupFiles dotenv/config --coverage"
|
|
33
63
|
},
|
|
34
64
|
"keywords": [
|
|
35
65
|
"typescript",
|
|
@@ -62,10 +92,10 @@
|
|
|
62
92
|
"@cspell/dict-software-terms": "^3.3.18",
|
|
63
93
|
"@cspell/dict-typescript": "^3.1.2",
|
|
64
94
|
"@eslint/js": "^9.14.0",
|
|
65
|
-
"@jest/globals": "29.7.0",
|
|
95
|
+
"@jest/globals": "^29.7.0",
|
|
66
96
|
"@mswjs/data": "0.16.1",
|
|
67
|
-
"@types/jest": "29.5.12",
|
|
68
97
|
"@types/node": "^20.11.19",
|
|
98
|
+
"cross-env": "^7.0.3",
|
|
69
99
|
"cspell": "^8.4.0",
|
|
70
100
|
"eslint": "^9.14.0",
|
|
71
101
|
"eslint-config-prettier": "^9.1.0",
|
|
@@ -73,13 +103,17 @@
|
|
|
73
103
|
"eslint-plugin-prettier": "^5.2.1",
|
|
74
104
|
"eslint-plugin-sonarjs": "^2.0.4",
|
|
75
105
|
"husky": "^9.0.11",
|
|
76
|
-
"jest": "29.7.0",
|
|
77
|
-
"jest-junit": "16.0.0",
|
|
78
|
-
"jest-md-dashboard": "0.8.0",
|
|
106
|
+
"jest": "^29.7.0",
|
|
107
|
+
"jest-junit": "^16.0.0",
|
|
108
|
+
"jest-md-dashboard": "^0.8.0",
|
|
79
109
|
"knip": "^5.0.1",
|
|
80
110
|
"lint-staged": "^15.2.2",
|
|
111
|
+
"msw": "^2.6.3",
|
|
112
|
+
"npm-run-all": "^4.1.5",
|
|
81
113
|
"prettier": "^3.3.3",
|
|
82
|
-
"
|
|
114
|
+
"simple-git": "^3.27.0",
|
|
115
|
+
"ts-jest": "^29.2.5",
|
|
116
|
+
"ts-node": "^10.9.2",
|
|
83
117
|
"tsup": "8.1.0",
|
|
84
118
|
"typescript": "^5.5.4",
|
|
85
119
|
"typescript-eslint": "^8.13.0"
|