@substrate-system/keys 0.2.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.
- package/LICENSE +99 -0
- package/README.md +688 -0
- package/dist/constants.cjs +64 -0
- package/dist/constants.cjs.map +7 -0
- package/dist/constants.d.ts +24 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +44 -0
- package/dist/constants.js.map +7 -0
- package/dist/constants.min.cjs +2 -0
- package/dist/constants.min.cjs.map +7 -0
- package/dist/constants.min.js +2 -0
- package/dist/constants.min.js.map +7 -0
- package/dist/index.cjs +480 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +191 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +493 -0
- package/dist/index.js.map +7 -0
- package/dist/index.min.cjs +2 -0
- package/dist/index.min.cjs.map +7 -0
- package/dist/index.min.js +4 -0
- package/dist/index.min.js.map +7 -0
- package/dist/meta.json +225 -0
- package/dist/types.cjs +57 -0
- package/dist/types.cjs.map +7 -0
- package/dist/types.d.ts +38 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +37 -0
- package/dist/types.js.map +7 -0
- package/dist/types.min.cjs +2 -0
- package/dist/types.min.cjs.map +7 -0
- package/dist/types.min.js +2 -0
- package/dist/types.min.js.map +7 -0
- package/dist/util.cjs +375 -0
- package/dist/util.cjs.map +7 -0
- package/dist/util.d.ts +89 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +373 -0
- package/dist/util.js.map +7 -0
- package/dist/util.min.cjs +4 -0
- package/dist/util.min.cjs.map +7 -0
- package/dist/util.min.js +4 -0
- package/dist/util.min.js.map +7 -0
- package/package.json +86 -0
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
var constants_exports = {};
|
|
20
|
+
__export(constants_exports, {
|
|
21
|
+
AES_GCM: () => AES_GCM,
|
|
22
|
+
BASE58_DID_PREFIX: () => BASE58_DID_PREFIX,
|
|
23
|
+
BLS_DID_PREFIX: () => BLS_DID_PREFIX,
|
|
24
|
+
DEFAULT_CHAR_SIZE: () => DEFAULT_CHAR_SIZE,
|
|
25
|
+
DEFAULT_ENC_NAME: () => DEFAULT_ENC_NAME,
|
|
26
|
+
DEFAULT_HASH_ALGORITHM: () => DEFAULT_HASH_ALGORITHM,
|
|
27
|
+
DEFAULT_RSA_SIZE: () => DEFAULT_RSA_SIZE,
|
|
28
|
+
DEFAULT_SIG_NAME: () => DEFAULT_SIG_NAME,
|
|
29
|
+
DEFAULT_SYMM_ALGORITHM: () => DEFAULT_SYMM_ALGORITHM,
|
|
30
|
+
DEFAULT_SYMM_LENGTH: () => DEFAULT_SYMM_LENGTH,
|
|
31
|
+
EDWARDS_DID_PREFIX: () => EDWARDS_DID_PREFIX,
|
|
32
|
+
IV_LENGTH: () => IV_LENGTH,
|
|
33
|
+
KEY_TYPE: () => KEY_TYPE,
|
|
34
|
+
RSA_ALGORITHM: () => RSA_ALGORITHM,
|
|
35
|
+
RSA_DID_PREFIX: () => RSA_DID_PREFIX,
|
|
36
|
+
RSA_HASHING_ALGORITHM: () => RSA_HASHING_ALGORITHM,
|
|
37
|
+
RSA_SIGN_ALGORITHM: () => RSA_SIGN_ALGORITHM,
|
|
38
|
+
SALT_LENGTH: () => SALT_LENGTH
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(constants_exports);
|
|
41
|
+
var import_types = require("./types.js");
|
|
42
|
+
const BASE58_DID_PREFIX = "did:key:z";
|
|
43
|
+
const RSA_ALGORITHM = "RSA-OAEP";
|
|
44
|
+
const RSA_SIGN_ALGORITHM = "RSASSA-PKCS1-v1_5";
|
|
45
|
+
const RSA_HASHING_ALGORITHM = "SHA-256";
|
|
46
|
+
const RSA_DID_PREFIX = new Uint8Array([0, 245, 2]);
|
|
47
|
+
const DEFAULT_RSA_SIZE = import_types.RsaSize.B2048;
|
|
48
|
+
const DEFAULT_HASH_ALGORITHM = import_types.HashAlg.SHA_256;
|
|
49
|
+
const DEFAULT_CHAR_SIZE = import_types.CharSize.B8;
|
|
50
|
+
const SALT_LENGTH = 128;
|
|
51
|
+
const AES_GCM = "AES-GCM";
|
|
52
|
+
const DEFAULT_SYMM_ALGORITHM = AES_GCM;
|
|
53
|
+
const DEFAULT_SYMM_LENGTH = 256;
|
|
54
|
+
const IV_LENGTH = 12;
|
|
55
|
+
const BLS_DID_PREFIX = new Uint8Array([234, 1]);
|
|
56
|
+
const EDWARDS_DID_PREFIX = new Uint8Array([237, 1]);
|
|
57
|
+
const KEY_TYPE = {
|
|
58
|
+
RSA: "rsa",
|
|
59
|
+
Edwards: "ed25519",
|
|
60
|
+
BLS: "bls12-381"
|
|
61
|
+
};
|
|
62
|
+
const DEFAULT_ENC_NAME = "encryption-key";
|
|
63
|
+
const DEFAULT_SIG_NAME = "signing-key";
|
|
64
|
+
//# sourceMappingURL=constants.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/constants.ts"],
|
|
4
|
+
"sourcesContent": ["import { RsaSize, HashAlg, CharSize } from './types.js'\n\nexport const BASE58_DID_PREFIX = 'did:key:z'\n\n// RSA\nexport const RSA_ALGORITHM = 'RSA-OAEP'\nexport const RSA_SIGN_ALGORITHM = 'RSASSA-PKCS1-v1_5'\nexport const RSA_HASHING_ALGORITHM = 'SHA-256'\nexport const RSA_DID_PREFIX = new Uint8Array([0x00, 0xf5, 0x02])\nexport const DEFAULT_RSA_SIZE = RsaSize.B2048\nexport const DEFAULT_HASH_ALGORITHM = HashAlg.SHA_256\nexport const DEFAULT_CHAR_SIZE = CharSize.B8\nexport const SALT_LENGTH = 128\n\n// AES\nexport const AES_GCM = 'AES-GCM' as const\nexport const DEFAULT_SYMM_ALGORITHM = AES_GCM\nexport const DEFAULT_SYMM_LENGTH = 256\nexport const IV_LENGTH = 12\n\n// Misc\nexport const BLS_DID_PREFIX = new Uint8Array([0xea, 0x01])\nexport const EDWARDS_DID_PREFIX = new Uint8Array([0xed, 0x01])\nexport const KEY_TYPE = {\n RSA: 'rsa',\n Edwards: 'ed25519',\n BLS: 'bls12-381'\n} as const\n\n// app specific\nexport const DEFAULT_ENC_NAME = 'encryption-key'\nexport const DEFAULT_SIG_NAME = 'signing-key'\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA2C;AAEpC,MAAM,oBAAoB;AAG1B,MAAM,gBAAgB;AACtB,MAAM,qBAAqB;AAC3B,MAAM,wBAAwB;AAC9B,MAAM,iBAAiB,IAAI,WAAW,CAAC,GAAM,KAAM,CAAI,CAAC;AACxD,MAAM,mBAAmB,qBAAQ;AACjC,MAAM,yBAAyB,qBAAQ;AACvC,MAAM,oBAAoB,sBAAS;AACnC,MAAM,cAAc;AAGpB,MAAM,UAAU;AAChB,MAAM,yBAAyB;AAC/B,MAAM,sBAAsB;AAC5B,MAAM,YAAY;AAGlB,MAAM,iBAAiB,IAAI,WAAW,CAAC,KAAM,CAAI,CAAC;AAClD,MAAM,qBAAqB,IAAI,WAAW,CAAC,KAAM,CAAI,CAAC;AACtD,MAAM,WAAW;AAAA,EACpB,KAAK;AAAA,EACL,SAAS;AAAA,EACT,KAAK;AACT;AAGO,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { RsaSize, HashAlg, CharSize } from './types.js';
|
|
2
|
+
export declare const BASE58_DID_PREFIX = "did:key:z";
|
|
3
|
+
export declare const RSA_ALGORITHM = "RSA-OAEP";
|
|
4
|
+
export declare const RSA_SIGN_ALGORITHM = "RSASSA-PKCS1-v1_5";
|
|
5
|
+
export declare const RSA_HASHING_ALGORITHM = "SHA-256";
|
|
6
|
+
export declare const RSA_DID_PREFIX: Uint8Array<ArrayBuffer>;
|
|
7
|
+
export declare const DEFAULT_RSA_SIZE = RsaSize.B2048;
|
|
8
|
+
export declare const DEFAULT_HASH_ALGORITHM = HashAlg.SHA_256;
|
|
9
|
+
export declare const DEFAULT_CHAR_SIZE = CharSize.B8;
|
|
10
|
+
export declare const SALT_LENGTH = 128;
|
|
11
|
+
export declare const AES_GCM: "AES-GCM";
|
|
12
|
+
export declare const DEFAULT_SYMM_ALGORITHM: "AES-GCM";
|
|
13
|
+
export declare const DEFAULT_SYMM_LENGTH = 256;
|
|
14
|
+
export declare const IV_LENGTH = 12;
|
|
15
|
+
export declare const BLS_DID_PREFIX: Uint8Array<ArrayBuffer>;
|
|
16
|
+
export declare const EDWARDS_DID_PREFIX: Uint8Array<ArrayBuffer>;
|
|
17
|
+
export declare const KEY_TYPE: {
|
|
18
|
+
readonly RSA: "rsa";
|
|
19
|
+
readonly Edwards: "ed25519";
|
|
20
|
+
readonly BLS: "bls12-381";
|
|
21
|
+
};
|
|
22
|
+
export declare const DEFAULT_ENC_NAME = "encryption-key";
|
|
23
|
+
export declare const DEFAULT_SIG_NAME = "signing-key";
|
|
24
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAEvD,eAAO,MAAM,iBAAiB,cAAc,CAAA;AAG5C,eAAO,MAAM,aAAa,aAAa,CAAA;AACvC,eAAO,MAAM,kBAAkB,sBAAsB,CAAA;AACrD,eAAO,MAAM,qBAAqB,YAAY,CAAA;AAC9C,eAAO,MAAM,cAAc,yBAAqC,CAAA;AAChE,eAAO,MAAM,gBAAgB,gBAAgB,CAAA;AAC7C,eAAO,MAAM,sBAAsB,kBAAkB,CAAA;AACrD,eAAO,MAAM,iBAAiB,cAAc,CAAA;AAC5C,eAAO,MAAM,WAAW,MAAM,CAAA;AAG9B,eAAO,MAAM,OAAO,EAAG,SAAkB,CAAA;AACzC,eAAO,MAAM,sBAAsB,WAAU,CAAA;AAC7C,eAAO,MAAM,mBAAmB,MAAM,CAAA;AACtC,eAAO,MAAM,SAAS,KAAK,CAAA;AAG3B,eAAO,MAAM,cAAc,yBAA+B,CAAA;AAC1D,eAAO,MAAM,kBAAkB,yBAA+B,CAAA;AAC9D,eAAO,MAAM,QAAQ;;;;CAIX,CAAA;AAGV,eAAO,MAAM,gBAAgB,mBAAmB,CAAA;AAChD,eAAO,MAAM,gBAAgB,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { RsaSize, HashAlg, CharSize } from "./types.js";
|
|
2
|
+
const BASE58_DID_PREFIX = "did:key:z";
|
|
3
|
+
const RSA_ALGORITHM = "RSA-OAEP";
|
|
4
|
+
const RSA_SIGN_ALGORITHM = "RSASSA-PKCS1-v1_5";
|
|
5
|
+
const RSA_HASHING_ALGORITHM = "SHA-256";
|
|
6
|
+
const RSA_DID_PREFIX = new Uint8Array([0, 245, 2]);
|
|
7
|
+
const DEFAULT_RSA_SIZE = RsaSize.B2048;
|
|
8
|
+
const DEFAULT_HASH_ALGORITHM = HashAlg.SHA_256;
|
|
9
|
+
const DEFAULT_CHAR_SIZE = CharSize.B8;
|
|
10
|
+
const SALT_LENGTH = 128;
|
|
11
|
+
const AES_GCM = "AES-GCM";
|
|
12
|
+
const DEFAULT_SYMM_ALGORITHM = AES_GCM;
|
|
13
|
+
const DEFAULT_SYMM_LENGTH = 256;
|
|
14
|
+
const IV_LENGTH = 12;
|
|
15
|
+
const BLS_DID_PREFIX = new Uint8Array([234, 1]);
|
|
16
|
+
const EDWARDS_DID_PREFIX = new Uint8Array([237, 1]);
|
|
17
|
+
const KEY_TYPE = {
|
|
18
|
+
RSA: "rsa",
|
|
19
|
+
Edwards: "ed25519",
|
|
20
|
+
BLS: "bls12-381"
|
|
21
|
+
};
|
|
22
|
+
const DEFAULT_ENC_NAME = "encryption-key";
|
|
23
|
+
const DEFAULT_SIG_NAME = "signing-key";
|
|
24
|
+
export {
|
|
25
|
+
AES_GCM,
|
|
26
|
+
BASE58_DID_PREFIX,
|
|
27
|
+
BLS_DID_PREFIX,
|
|
28
|
+
DEFAULT_CHAR_SIZE,
|
|
29
|
+
DEFAULT_ENC_NAME,
|
|
30
|
+
DEFAULT_HASH_ALGORITHM,
|
|
31
|
+
DEFAULT_RSA_SIZE,
|
|
32
|
+
DEFAULT_SIG_NAME,
|
|
33
|
+
DEFAULT_SYMM_ALGORITHM,
|
|
34
|
+
DEFAULT_SYMM_LENGTH,
|
|
35
|
+
EDWARDS_DID_PREFIX,
|
|
36
|
+
IV_LENGTH,
|
|
37
|
+
KEY_TYPE,
|
|
38
|
+
RSA_ALGORITHM,
|
|
39
|
+
RSA_DID_PREFIX,
|
|
40
|
+
RSA_HASHING_ALGORITHM,
|
|
41
|
+
RSA_SIGN_ALGORITHM,
|
|
42
|
+
SALT_LENGTH
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/constants.ts"],
|
|
4
|
+
"sourcesContent": ["import { RsaSize, HashAlg, CharSize } from './types.js'\n\nexport const BASE58_DID_PREFIX = 'did:key:z'\n\n// RSA\nexport const RSA_ALGORITHM = 'RSA-OAEP'\nexport const RSA_SIGN_ALGORITHM = 'RSASSA-PKCS1-v1_5'\nexport const RSA_HASHING_ALGORITHM = 'SHA-256'\nexport const RSA_DID_PREFIX = new Uint8Array([0x00, 0xf5, 0x02])\nexport const DEFAULT_RSA_SIZE = RsaSize.B2048\nexport const DEFAULT_HASH_ALGORITHM = HashAlg.SHA_256\nexport const DEFAULT_CHAR_SIZE = CharSize.B8\nexport const SALT_LENGTH = 128\n\n// AES\nexport const AES_GCM = 'AES-GCM' as const\nexport const DEFAULT_SYMM_ALGORITHM = AES_GCM\nexport const DEFAULT_SYMM_LENGTH = 256\nexport const IV_LENGTH = 12\n\n// Misc\nexport const BLS_DID_PREFIX = new Uint8Array([0xea, 0x01])\nexport const EDWARDS_DID_PREFIX = new Uint8Array([0xed, 0x01])\nexport const KEY_TYPE = {\n RSA: 'rsa',\n Edwards: 'ed25519',\n BLS: 'bls12-381'\n} as const\n\n// app specific\nexport const DEFAULT_ENC_NAME = 'encryption-key'\nexport const DEFAULT_SIG_NAME = 'signing-key'\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS,SAAS,gBAAgB;AAEpC,MAAM,oBAAoB;AAG1B,MAAM,gBAAgB;AACtB,MAAM,qBAAqB;AAC3B,MAAM,wBAAwB;AAC9B,MAAM,iBAAiB,IAAI,WAAW,CAAC,GAAM,KAAM,CAAI,CAAC;AACxD,MAAM,mBAAmB,QAAQ;AACjC,MAAM,yBAAyB,QAAQ;AACvC,MAAM,oBAAoB,SAAS;AACnC,MAAM,cAAc;AAGpB,MAAM,UAAU;AAChB,MAAM,yBAAyB;AAC/B,MAAM,sBAAsB;AAC5B,MAAM,YAAY;AAGlB,MAAM,iBAAiB,IAAI,WAAW,CAAC,KAAM,CAAI,CAAC;AAClD,MAAM,qBAAqB,IAAI,WAAW,CAAC,KAAM,CAAI,CAAC;AACtD,MAAM,WAAW;AAAA,EACpB,KAAK;AAAA,EACL,SAAS;AAAA,EACT,KAAK;AACT;AAGO,MAAM,mBAAmB;AACzB,MAAM,mBAAmB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var n=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var c=(o,t)=>{for(var e in t)n(o,e,{get:t[e],enumerable:!0})},p=(o,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let _ of E(t))!x.call(o,_)&&_!==e&&n(o,_,{get:()=>t[_],enumerable:!(r=s(t,_))||r.enumerable});return o};var R=o=>p(n({},"__esModule",{value:!0}),o);var B={};c(B,{AES_GCM:()=>S,BASE58_DID_PREFIX:()=>I,BLS_DID_PREFIX:()=>y,DEFAULT_CHAR_SIZE:()=>a,DEFAULT_ENC_NAME:()=>C,DEFAULT_HASH_ALGORITHM:()=>M,DEFAULT_RSA_SIZE:()=>G,DEFAULT_SIG_NAME:()=>O,DEFAULT_SYMM_ALGORITHM:()=>i,DEFAULT_SYMM_LENGTH:()=>U,EDWARDS_DID_PREFIX:()=>P,IV_LENGTH:()=>N,KEY_TYPE:()=>d,RSA_ALGORITHM:()=>L,RSA_DID_PREFIX:()=>H,RSA_HASHING_ALGORITHM:()=>T,RSA_SIGN_ALGORITHM:()=>D,SALT_LENGTH:()=>F});module.exports=R(B);var A=require("./types.js");const I="did:key:z",L="RSA-OAEP",D="RSASSA-PKCS1-v1_5",T="SHA-256",H=new Uint8Array([0,245,2]),G=A.RsaSize.B2048,M=A.HashAlg.SHA_256,a=A.CharSize.B8,F=128,S="AES-GCM",i=S,U=256,N=12,y=new Uint8Array([234,1]),P=new Uint8Array([237,1]),d={RSA:"rsa",Edwards:"ed25519",BLS:"bls12-381"},C="encryption-key",O="signing-key";
|
|
2
|
+
//# sourceMappingURL=constants.min.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/constants.ts"],
|
|
4
|
+
"sourcesContent": ["import { RsaSize, HashAlg, CharSize } from './types.js'\n\nexport const BASE58_DID_PREFIX = 'did:key:z'\n\n// RSA\nexport const RSA_ALGORITHM = 'RSA-OAEP'\nexport const RSA_SIGN_ALGORITHM = 'RSASSA-PKCS1-v1_5'\nexport const RSA_HASHING_ALGORITHM = 'SHA-256'\nexport const RSA_DID_PREFIX = new Uint8Array([0x00, 0xf5, 0x02])\nexport const DEFAULT_RSA_SIZE = RsaSize.B2048\nexport const DEFAULT_HASH_ALGORITHM = HashAlg.SHA_256\nexport const DEFAULT_CHAR_SIZE = CharSize.B8\nexport const SALT_LENGTH = 128\n\n// AES\nexport const AES_GCM = 'AES-GCM' as const\nexport const DEFAULT_SYMM_ALGORITHM = AES_GCM\nexport const DEFAULT_SYMM_LENGTH = 256\nexport const IV_LENGTH = 12\n\n// Misc\nexport const BLS_DID_PREFIX = new Uint8Array([0xea, 0x01])\nexport const EDWARDS_DID_PREFIX = new Uint8Array([0xed, 0x01])\nexport const KEY_TYPE = {\n RSA: 'rsa',\n Edwards: 'ed25519',\n BLS: 'bls12-381'\n} as const\n\n// app specific\nexport const DEFAULT_ENC_NAME = 'encryption-key'\nexport const DEFAULT_SIG_NAME = 'signing-key'\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,sBAAAC,EAAA,mBAAAC,EAAA,sBAAAC,EAAA,qBAAAC,EAAA,2BAAAC,EAAA,qBAAAC,EAAA,qBAAAC,EAAA,2BAAAC,EAAA,wBAAAC,EAAA,uBAAAC,EAAA,cAAAC,EAAA,aAAAC,EAAA,kBAAAC,EAAA,mBAAAC,EAAA,0BAAAC,EAAA,uBAAAC,EAAA,gBAAAC,IAAA,eAAAC,EAAApB,GAAA,IAAAqB,EAA2C,sBAEpC,MAAMlB,EAAoB,YAGpBY,EAAgB,WAChBG,EAAqB,oBACrBD,EAAwB,UACxBD,EAAiB,IAAI,WAAW,CAAC,EAAM,IAAM,CAAI,CAAC,EAClDR,EAAmB,UAAQ,MAC3BD,EAAyB,UAAQ,QACjCF,EAAoB,WAAS,GAC7Bc,EAAc,IAGdjB,EAAU,UACVQ,EAAyBR,EACzBS,EAAsB,IACtBE,EAAY,GAGZT,EAAiB,IAAI,WAAW,CAAC,IAAM,CAAI,CAAC,EAC5CQ,EAAqB,IAAI,WAAW,CAAC,IAAM,CAAI,CAAC,EAChDE,EAAW,CACpB,IAAK,MACL,QAAS,UACT,IAAK,WACT,EAGaR,EAAmB,iBACnBG,EAAmB",
|
|
6
|
+
"names": ["constants_exports", "__export", "AES_GCM", "BASE58_DID_PREFIX", "BLS_DID_PREFIX", "DEFAULT_CHAR_SIZE", "DEFAULT_ENC_NAME", "DEFAULT_HASH_ALGORITHM", "DEFAULT_RSA_SIZE", "DEFAULT_SIG_NAME", "DEFAULT_SYMM_ALGORITHM", "DEFAULT_SYMM_LENGTH", "EDWARDS_DID_PREFIX", "IV_LENGTH", "KEY_TYPE", "RSA_ALGORITHM", "RSA_DID_PREFIX", "RSA_HASHING_ALGORITHM", "RSA_SIGN_ALGORITHM", "SALT_LENGTH", "__toCommonJS", "import_types"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e="did:key:z",_="RSA-OAEP",x="RSASSA-PKCS1-v1_5",E="SHA-256",S=new Uint8Array([0,245,2]),c=2048,s="SHA-256",H=8,I=128,t="AES-GCM",y=t,D=256,T=12,B=new Uint8Array([234,1]),M=new Uint8Array([237,1]),i={RSA:"rsa",Edwards:"ed25519",BLS:"bls12-381"},R="encryption-key",G="signing-key";export{t as AES_GCM,e as BASE58_DID_PREFIX,B as BLS_DID_PREFIX,H as DEFAULT_CHAR_SIZE,R as DEFAULT_ENC_NAME,s as DEFAULT_HASH_ALGORITHM,c as DEFAULT_RSA_SIZE,G as DEFAULT_SIG_NAME,y as DEFAULT_SYMM_ALGORITHM,D as DEFAULT_SYMM_LENGTH,M as EDWARDS_DID_PREFIX,T as IV_LENGTH,i as KEY_TYPE,_ as RSA_ALGORITHM,S as RSA_DID_PREFIX,E as RSA_HASHING_ALGORITHM,x as RSA_SIGN_ALGORITHM,I as SALT_LENGTH};
|
|
2
|
+
//# sourceMappingURL=constants.min.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/constants.ts"],
|
|
4
|
+
"sourcesContent": ["import { RsaSize, HashAlg, CharSize } from './types.js'\n\nexport const BASE58_DID_PREFIX = 'did:key:z'\n\n// RSA\nexport const RSA_ALGORITHM = 'RSA-OAEP'\nexport const RSA_SIGN_ALGORITHM = 'RSASSA-PKCS1-v1_5'\nexport const RSA_HASHING_ALGORITHM = 'SHA-256'\nexport const RSA_DID_PREFIX = new Uint8Array([0x00, 0xf5, 0x02])\nexport const DEFAULT_RSA_SIZE = RsaSize.B2048\nexport const DEFAULT_HASH_ALGORITHM = HashAlg.SHA_256\nexport const DEFAULT_CHAR_SIZE = CharSize.B8\nexport const SALT_LENGTH = 128\n\n// AES\nexport const AES_GCM = 'AES-GCM' as const\nexport const DEFAULT_SYMM_ALGORITHM = AES_GCM\nexport const DEFAULT_SYMM_LENGTH = 256\nexport const IV_LENGTH = 12\n\n// Misc\nexport const BLS_DID_PREFIX = new Uint8Array([0xea, 0x01])\nexport const EDWARDS_DID_PREFIX = new Uint8Array([0xed, 0x01])\nexport const KEY_TYPE = {\n RSA: 'rsa',\n Edwards: 'ed25519',\n BLS: 'bls12-381'\n} as const\n\n// app specific\nexport const DEFAULT_ENC_NAME = 'encryption-key'\nexport const DEFAULT_SIG_NAME = 'signing-key'\n"],
|
|
5
|
+
"mappings": "AAEO,IAAMA,EAAoB,YAGpBC,EAAgB,WAChBC,EAAqB,oBACrBC,EAAwB,UACxBC,EAAiB,IAAI,WAAW,CAAC,EAAM,IAAM,CAAI,CAAC,EAClDC,OACAC,YACAC,IACAC,EAAc,IAGdC,EAAU,UACVC,EAAyBD,EACzBE,EAAsB,IACtBC,EAAY,GAGZC,EAAiB,IAAI,WAAW,CAAC,IAAM,CAAI,CAAC,EAC5CC,EAAqB,IAAI,WAAW,CAAC,IAAM,CAAI,CAAC,EAChDC,EAAW,CACpB,IAAK,MACL,QAAS,UACT,IAAK,WACT,EAGaC,EAAmB,iBACnBC,EAAmB",
|
|
6
|
+
"names": ["BASE58_DID_PREFIX", "RSA_ALGORITHM", "RSA_SIGN_ALGORITHM", "RSA_HASHING_ALGORITHM", "RSA_DID_PREFIX", "DEFAULT_RSA_SIZE", "DEFAULT_HASH_ALGORITHM", "DEFAULT_CHAR_SIZE", "SALT_LENGTH", "AES_GCM", "DEFAULT_SYMM_ALGORITHM", "DEFAULT_SYMM_LENGTH", "IV_LENGTH", "BLS_DID_PREFIX", "EDWARDS_DID_PREFIX", "KEY_TYPE", "DEFAULT_ENC_NAME", "DEFAULT_SIG_NAME"]
|
|
7
|
+
}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,480 @@
|
|
|
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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
23
|
+
var index_exports = {};
|
|
24
|
+
__export(index_exports, {
|
|
25
|
+
AES: () => AES,
|
|
26
|
+
Keys: () => Keys,
|
|
27
|
+
encryptKeyTo: () => encryptKeyTo,
|
|
28
|
+
encryptTo: () => encryptTo,
|
|
29
|
+
getDeviceName: () => getDeviceName,
|
|
30
|
+
getPublicKeyAsArrayBuffer: () => import_util.getPublicKeyAsArrayBuffer,
|
|
31
|
+
getPublicKeyAsUint8Array: () => import_util2.getPublicKeyAsUint8Array,
|
|
32
|
+
publicKeyToDid: () => import_util.publicKeyToDid,
|
|
33
|
+
verify: () => verify
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
var import_one_webcrypto = require("@bicycle-codes/one-webcrypto");
|
|
37
|
+
var import_uint8arrays = require("uint8arrays");
|
|
38
|
+
var import_idb_keyval = require("idb-keyval");
|
|
39
|
+
var import_constants = require("./constants.js");
|
|
40
|
+
var import_types = require("./types.js");
|
|
41
|
+
var import_util = require("./util.js");
|
|
42
|
+
__reExport(index_exports, require("./constants.js"), module.exports);
|
|
43
|
+
var import_util2 = require("./util.js");
|
|
44
|
+
const _Keys = class _Keys {
|
|
45
|
+
// in memory only?
|
|
46
|
+
constructor(opts) {
|
|
47
|
+
__publicField(this, "_encryptKey");
|
|
48
|
+
__publicField(this, "_signKey");
|
|
49
|
+
// a cache for indexedDB
|
|
50
|
+
__publicField(this, "persisted");
|
|
51
|
+
__publicField(this, "ENCRYPTION_KEY_NAME", import_constants.DEFAULT_ENC_NAME);
|
|
52
|
+
__publicField(this, "SIGNING_KEY_NAME", import_constants.DEFAULT_SIG_NAME);
|
|
53
|
+
__publicField(this, "DID");
|
|
54
|
+
__publicField(this, "session");
|
|
55
|
+
/**
|
|
56
|
+
* Get the public encryption key as a string.
|
|
57
|
+
*
|
|
58
|
+
* @param {SupportedEncodings} [format] Optional string format for
|
|
59
|
+
* `uint8arrays`. Defaults to base64.
|
|
60
|
+
* @returns {string} Return a string b/c mostly would use this for
|
|
61
|
+
* serializing the public encryption key.
|
|
62
|
+
*/
|
|
63
|
+
__publicField(this, "getPublicEncryptKey", Object.assign(
|
|
64
|
+
async (format) => {
|
|
65
|
+
const { publicKey } = this._encryptKey;
|
|
66
|
+
const spki = await import_one_webcrypto.webcrypto.subtle.exportKey(
|
|
67
|
+
"spki",
|
|
68
|
+
publicKey
|
|
69
|
+
);
|
|
70
|
+
return format ? (0, import_uint8arrays.toString)(new Uint8Array(spki), format) : (0, import_util.toBase64)(spki);
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
uint8Array: /* @__PURE__ */ __name(async () => {
|
|
74
|
+
const { publicKey } = this._encryptKey;
|
|
75
|
+
const arr = await (0, import_util.getPublicKeyAsUint8Array)(publicKey);
|
|
76
|
+
return arr;
|
|
77
|
+
}, "uint8Array")
|
|
78
|
+
}
|
|
79
|
+
));
|
|
80
|
+
__publicField(this, "decrypt", Object.assign(
|
|
81
|
+
/**
|
|
82
|
+
* Expect the given cipher content to be the format returned by
|
|
83
|
+
* encryptTo`. That is, encrypted AES key + `iv` + encrypted content.
|
|
84
|
+
*/
|
|
85
|
+
async (msg, keysize) => {
|
|
86
|
+
const length = keysize || import_constants.DEFAULT_SYMM_LENGTH;
|
|
87
|
+
const cipherText = (0, import_util.normalizeToBuf)(msg, import_util.base64ToArrBuf);
|
|
88
|
+
const key = cipherText.slice(0, length);
|
|
89
|
+
const data = cipherText.slice(length);
|
|
90
|
+
const decryptedKey = await this.decryptKey(key);
|
|
91
|
+
const decryptedContent = await AES.decrypt(data, decryptedKey);
|
|
92
|
+
return decryptedContent;
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
asString: /* @__PURE__ */ __name(async (msg, keysize) => {
|
|
96
|
+
const dec = await this.decrypt(msg, keysize);
|
|
97
|
+
return (0, import_uint8arrays.toString)(dec);
|
|
98
|
+
}, "asString")
|
|
99
|
+
}
|
|
100
|
+
));
|
|
101
|
+
__publicField(this, "sign", Object.assign(
|
|
102
|
+
/**
|
|
103
|
+
* Sign the message, and return the signature as a `Uint8Array`.
|
|
104
|
+
*/
|
|
105
|
+
async (msg, charsize = import_constants.DEFAULT_CHAR_SIZE) => {
|
|
106
|
+
const key = this._signKey;
|
|
107
|
+
const sig = await import_util.rsaOperations.sign(
|
|
108
|
+
msg,
|
|
109
|
+
key.privateKey,
|
|
110
|
+
charsize
|
|
111
|
+
);
|
|
112
|
+
return new Uint8Array(sig);
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
/**
|
|
116
|
+
* Sign a message, return the signature as a base64 encoded string.
|
|
117
|
+
*
|
|
118
|
+
* @param {Msg} msg The message to sign
|
|
119
|
+
* @param {CharSize} [charsize] Character size
|
|
120
|
+
* @returns {Promise<string>}
|
|
121
|
+
*/
|
|
122
|
+
asString: /* @__PURE__ */ __name(async (msg, charsize) => {
|
|
123
|
+
const sig = await this.sign(msg, charsize);
|
|
124
|
+
return (0, import_util.toBase64)(sig);
|
|
125
|
+
}, "asString")
|
|
126
|
+
}
|
|
127
|
+
));
|
|
128
|
+
/**
|
|
129
|
+
* Decrypt the given encrypted AES key.
|
|
130
|
+
* Return the key as `Uint8Array`.
|
|
131
|
+
*/
|
|
132
|
+
__publicField(this, "decryptKey", Object.assign(
|
|
133
|
+
async (key) => {
|
|
134
|
+
const decrypted = await import_util.rsaOperations.decrypt(
|
|
135
|
+
key,
|
|
136
|
+
this.privateEncryptKey
|
|
137
|
+
);
|
|
138
|
+
return decrypted;
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
/**
|
|
142
|
+
* Decrypt the given AES key, return the result as a string.
|
|
143
|
+
*/
|
|
144
|
+
asString: /* @__PURE__ */ __name(async (msg, format) => {
|
|
145
|
+
const decrypted = await import_util.rsaOperations.decrypt(
|
|
146
|
+
msg,
|
|
147
|
+
this.privateEncryptKey
|
|
148
|
+
);
|
|
149
|
+
return (0, import_uint8arrays.toString)(decrypted, format);
|
|
150
|
+
}, "asString")
|
|
151
|
+
}
|
|
152
|
+
));
|
|
153
|
+
const { keys } = opts;
|
|
154
|
+
this._encryptKey = keys.encrypt;
|
|
155
|
+
this._signKey = keys.sign;
|
|
156
|
+
this.DID = opts.did;
|
|
157
|
+
this.persisted = opts.persisted;
|
|
158
|
+
this.session = opts.session ?? false;
|
|
159
|
+
_Keys._instance = this;
|
|
160
|
+
}
|
|
161
|
+
get signKeypair() {
|
|
162
|
+
return {
|
|
163
|
+
privateKey: this.privateSignKey,
|
|
164
|
+
publicKey: this.publicSignKey
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
get encryptKeypair() {
|
|
168
|
+
return {
|
|
169
|
+
privateKey: this.privateEncryptKey,
|
|
170
|
+
publicKey: this.publicEncryptKey
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
get publicSignKey() {
|
|
174
|
+
return this._signKey.publicKey;
|
|
175
|
+
}
|
|
176
|
+
get privateSignKey() {
|
|
177
|
+
return this._signKey.privateKey;
|
|
178
|
+
}
|
|
179
|
+
get privateEncryptKey() {
|
|
180
|
+
return this._encryptKey.privateKey;
|
|
181
|
+
}
|
|
182
|
+
get publicEncryptKey() {
|
|
183
|
+
return this._encryptKey.publicKey;
|
|
184
|
+
}
|
|
185
|
+
get deviceName() {
|
|
186
|
+
return _Keys.deviceName(this.DID);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Delete the keys stored in indexedDB.
|
|
190
|
+
*/
|
|
191
|
+
async delete() {
|
|
192
|
+
await (0, import_idb_keyval.delMany)([this.ENCRYPTION_KEY_NAME, this.SIGNING_KEY_NAME]);
|
|
193
|
+
this.persisted = false;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Return a 32-character, DNS-friendly hash of the given DID.
|
|
197
|
+
*
|
|
198
|
+
* @param {DID} did a DID format string
|
|
199
|
+
* @returns {string} 32 character, base32 hash of the DID
|
|
200
|
+
*/
|
|
201
|
+
static deviceName(did) {
|
|
202
|
+
return getDeviceName(did);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Create a new `Keys` instance.
|
|
206
|
+
*
|
|
207
|
+
* @returns {Promise<Keys>}
|
|
208
|
+
*/
|
|
209
|
+
static async create(opts = { session: false }) {
|
|
210
|
+
const encryptionKeypair = await makeRSAKeypair(
|
|
211
|
+
import_constants.DEFAULT_RSA_SIZE,
|
|
212
|
+
import_constants.DEFAULT_HASH_ALGORITHM,
|
|
213
|
+
import_types.KeyUse.Encrypt
|
|
214
|
+
);
|
|
215
|
+
const signingKeypair = await makeRSAKeypair(
|
|
216
|
+
import_constants.DEFAULT_RSA_SIZE,
|
|
217
|
+
import_constants.DEFAULT_HASH_ALGORITHM,
|
|
218
|
+
import_types.KeyUse.Sign
|
|
219
|
+
);
|
|
220
|
+
const { session } = opts;
|
|
221
|
+
const publicSigningKey = await (0, import_util.getPublicKeyAsArrayBuffer)(signingKeypair);
|
|
222
|
+
const did = await (0, import_util.publicKeyToDid)(new Uint8Array(publicSigningKey), "rsa");
|
|
223
|
+
const keys = new _Keys({
|
|
224
|
+
keys: { encrypt: encryptionKeypair, sign: signingKeypair },
|
|
225
|
+
did,
|
|
226
|
+
persisted: false,
|
|
227
|
+
session
|
|
228
|
+
});
|
|
229
|
+
return keys;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Save this keys instance to `indexedDB`.
|
|
233
|
+
*/
|
|
234
|
+
async persist() {
|
|
235
|
+
if (this.session) return;
|
|
236
|
+
await Promise.all([
|
|
237
|
+
(0, import_idb_keyval.set)(this.ENCRYPTION_KEY_NAME, this._encryptKey),
|
|
238
|
+
(0, import_idb_keyval.set)(this.SIGNING_KEY_NAME, this._signKey)
|
|
239
|
+
]);
|
|
240
|
+
this.persisted = true;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Return a 32-character, DNS friendly hash of the public signing key.
|
|
244
|
+
*
|
|
245
|
+
* @returns {Promise<string>}
|
|
246
|
+
*/
|
|
247
|
+
async getDeviceName() {
|
|
248
|
+
return _Keys.deviceName(this.DID);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Restore some keys from indexedDB, or create a new keypair if it doesn't
|
|
252
|
+
* exist yet.
|
|
253
|
+
*
|
|
254
|
+
* @param {{ encryptionKeyName, signingKeyName }} opts Strings to use as
|
|
255
|
+
* keys in indexedDB.
|
|
256
|
+
* @returns {Promise<Keys>}
|
|
257
|
+
*/
|
|
258
|
+
static async load(opts = {
|
|
259
|
+
encryptionKeyName: import_constants.DEFAULT_ENC_NAME,
|
|
260
|
+
signingKeyName: import_constants.DEFAULT_SIG_NAME,
|
|
261
|
+
session: false
|
|
262
|
+
}) {
|
|
263
|
+
if (_Keys._instance) return _Keys._instance;
|
|
264
|
+
let persisted = true;
|
|
265
|
+
let encKeys = await (0, import_idb_keyval.get)(
|
|
266
|
+
opts.encryptionKeyName || import_constants.DEFAULT_ENC_NAME
|
|
267
|
+
);
|
|
268
|
+
let signKeys = await (0, import_idb_keyval.get)(
|
|
269
|
+
opts.signingKeyName || import_constants.DEFAULT_SIG_NAME
|
|
270
|
+
);
|
|
271
|
+
if (!encKeys) {
|
|
272
|
+
persisted = false;
|
|
273
|
+
encKeys = await makeRSAKeypair(
|
|
274
|
+
import_constants.DEFAULT_RSA_SIZE,
|
|
275
|
+
import_constants.DEFAULT_HASH_ALGORITHM,
|
|
276
|
+
import_types.KeyUse.Encrypt
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
if (!signKeys) {
|
|
280
|
+
persisted = false;
|
|
281
|
+
signKeys = await makeRSAKeypair(
|
|
282
|
+
import_constants.DEFAULT_RSA_SIZE,
|
|
283
|
+
import_constants.DEFAULT_HASH_ALGORITHM,
|
|
284
|
+
import_types.KeyUse.Sign
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
const publicKey = await (0, import_util.getPublicKeyAsArrayBuffer)(signKeys);
|
|
288
|
+
const did = await (0, import_util.publicKeyToDid)(new Uint8Array(publicKey), "rsa");
|
|
289
|
+
const keys = new _Keys({
|
|
290
|
+
keys: { encrypt: encKeys, sign: signKeys },
|
|
291
|
+
did,
|
|
292
|
+
persisted,
|
|
293
|
+
session: opts.session ?? false
|
|
294
|
+
});
|
|
295
|
+
return keys;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Serialize this keys instance. Will return an object of
|
|
299
|
+
* { DID, publicEncryptionKey }, where DID is the public signature key,
|
|
300
|
+
* and `publicEncryptKey` is the encryption key, `base64` encoded.
|
|
301
|
+
* @returns {Promise<{ DID:DID, publicEncryptKey:string }>}
|
|
302
|
+
*/
|
|
303
|
+
async toJson() {
|
|
304
|
+
const pubEnc = await this.getPublicEncryptKey();
|
|
305
|
+
const did = this.DID;
|
|
306
|
+
return {
|
|
307
|
+
publicEncryptKey: pubEnc,
|
|
308
|
+
DID: did
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
__name(_Keys, "Keys");
|
|
313
|
+
__publicField(_Keys, "_instance");
|
|
314
|
+
let Keys = _Keys;
|
|
315
|
+
async function makeRSAKeypair(size, hashAlg, use) {
|
|
316
|
+
if (!Object.values(import_types.KeyUse).includes(use)) {
|
|
317
|
+
throw new Error("invalid key use");
|
|
318
|
+
}
|
|
319
|
+
const alg = use === import_types.KeyUse.Encrypt ? import_constants.RSA_ALGORITHM : import_constants.RSA_SIGN_ALGORITHM;
|
|
320
|
+
const uses = use === import_types.KeyUse.Encrypt ? ["encrypt", "decrypt"] : ["sign", "verify"];
|
|
321
|
+
return import_one_webcrypto.webcrypto.subtle.generateKey({
|
|
322
|
+
name: alg,
|
|
323
|
+
modulusLength: size,
|
|
324
|
+
publicExponent: publicExponent(),
|
|
325
|
+
hash: { name: hashAlg }
|
|
326
|
+
}, false, uses);
|
|
327
|
+
}
|
|
328
|
+
__name(makeRSAKeypair, "makeRSAKeypair");
|
|
329
|
+
function publicExponent() {
|
|
330
|
+
return new Uint8Array([1, 0, 1]);
|
|
331
|
+
}
|
|
332
|
+
__name(publicExponent, "publicExponent");
|
|
333
|
+
async function verify(msg, sig, signingDid) {
|
|
334
|
+
const _key = (0, import_util.didToPublicKey)(signingDid);
|
|
335
|
+
const key = await (0, import_util.importPublicKey)(
|
|
336
|
+
_key.publicKey.buffer,
|
|
337
|
+
import_types.HashAlg.SHA_256,
|
|
338
|
+
import_types.KeyUse.Sign
|
|
339
|
+
);
|
|
340
|
+
try {
|
|
341
|
+
const isOk = import_util.rsaOperations.verify(msg, sig, key);
|
|
342
|
+
return isOk;
|
|
343
|
+
} catch (_err) {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
__name(verify, "verify");
|
|
348
|
+
async function encryptTo(opts, aesKey) {
|
|
349
|
+
const { content, publicKey } = opts;
|
|
350
|
+
const key = aesKey || await AES.create();
|
|
351
|
+
const encryptedContent = await AES.encrypt(
|
|
352
|
+
typeof content === "string" ? (0, import_uint8arrays.fromString)(content) : content,
|
|
353
|
+
typeof key === "string" ? await AES.import(key) : key
|
|
354
|
+
);
|
|
355
|
+
const encryptedKey = await encryptKeyTo({ key, publicKey });
|
|
356
|
+
return (0, import_util.joinBufs)(encryptedKey, encryptedContent);
|
|
357
|
+
}
|
|
358
|
+
__name(encryptTo, "encryptTo");
|
|
359
|
+
encryptTo.asString = async function(opts, aesKey) {
|
|
360
|
+
const { content, publicKey } = opts;
|
|
361
|
+
const key = aesKey || await AES.create();
|
|
362
|
+
const encryptedContent = await AES.encrypt(
|
|
363
|
+
typeof content === "string" ? (0, import_uint8arrays.fromString)(content) : content,
|
|
364
|
+
typeof key === "string" ? await AES.import(key) : key,
|
|
365
|
+
"arraybuffer"
|
|
366
|
+
);
|
|
367
|
+
const encryptedKey = await encryptKeyTo({ key, publicKey });
|
|
368
|
+
const joined = (0, import_util.joinBufs)(encryptedKey, encryptedContent);
|
|
369
|
+
return (0, import_uint8arrays.toString)(new Uint8Array(joined), "base64pad");
|
|
370
|
+
};
|
|
371
|
+
const AES = {
|
|
372
|
+
create(opts = {
|
|
373
|
+
alg: import_constants.DEFAULT_SYMM_ALGORITHM,
|
|
374
|
+
length: import_constants.DEFAULT_SYMM_LENGTH
|
|
375
|
+
}) {
|
|
376
|
+
return import_one_webcrypto.webcrypto.subtle.generateKey({
|
|
377
|
+
name: opts.alg,
|
|
378
|
+
length: opts.length
|
|
379
|
+
}, true, ["encrypt", "decrypt"]);
|
|
380
|
+
},
|
|
381
|
+
export: Object.assign(
|
|
382
|
+
async (key) => {
|
|
383
|
+
const raw = await import_one_webcrypto.webcrypto.subtle.exportKey("raw", key);
|
|
384
|
+
return new Uint8Array(raw);
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
asString: /* @__PURE__ */ __name(async (key, format) => {
|
|
388
|
+
const raw = await AES.export(key);
|
|
389
|
+
return format ? (0, import_uint8arrays.toString)(raw, format) : (0, import_util.toBase64)(raw);
|
|
390
|
+
}, "asString")
|
|
391
|
+
}
|
|
392
|
+
),
|
|
393
|
+
import(key) {
|
|
394
|
+
return importAesKey(typeof key === "string" ? (0, import_util.base64ToArrBuf)(key) : key);
|
|
395
|
+
},
|
|
396
|
+
async exportAsString(key) {
|
|
397
|
+
const raw = await AES.export(key);
|
|
398
|
+
return (0, import_util.toBase64)(raw);
|
|
399
|
+
},
|
|
400
|
+
encrypt,
|
|
401
|
+
async decrypt(encryptedData, cryptoKey, iv) {
|
|
402
|
+
const key = (0, import_util.isCryptoKey)(cryptoKey) ? cryptoKey : await importAesKey(cryptoKey);
|
|
403
|
+
const decrypted = iv ? await import_one_webcrypto.webcrypto.subtle.decrypt(
|
|
404
|
+
{
|
|
405
|
+
name: import_constants.AES_GCM,
|
|
406
|
+
iv
|
|
407
|
+
},
|
|
408
|
+
key,
|
|
409
|
+
typeof encryptedData === "string" ? (0, import_uint8arrays.fromString)(encryptedData) : encryptedData
|
|
410
|
+
) : await decryptBytes(encryptedData, key);
|
|
411
|
+
return new Uint8Array(decrypted);
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
async function encryptKeyTo({ key, publicKey }, format) {
|
|
415
|
+
let _key;
|
|
416
|
+
if (key instanceof CryptoKey) {
|
|
417
|
+
_key = await AES.export(key);
|
|
418
|
+
} else {
|
|
419
|
+
_key = key;
|
|
420
|
+
}
|
|
421
|
+
const buf = await import_util.rsaOperations.encrypt(_key, publicKey);
|
|
422
|
+
if (format && format === "arraybuffer") return buf;
|
|
423
|
+
return new Uint8Array(buf);
|
|
424
|
+
}
|
|
425
|
+
__name(encryptKeyTo, "encryptKeyTo");
|
|
426
|
+
encryptKeyTo.asString = async function({ key, publicKey }, format) {
|
|
427
|
+
const asArr = await encryptKeyTo({ key, publicKey });
|
|
428
|
+
return format ? (0, import_uint8arrays.toString)(asArr, format) : (0, import_util.toBase64)(asArr);
|
|
429
|
+
};
|
|
430
|
+
function importAesKey(key, length) {
|
|
431
|
+
return import_one_webcrypto.webcrypto.subtle.importKey(
|
|
432
|
+
"raw",
|
|
433
|
+
key,
|
|
434
|
+
{
|
|
435
|
+
name: import_constants.AES_GCM,
|
|
436
|
+
length: length || import_types.SymmKeyLength.B256
|
|
437
|
+
},
|
|
438
|
+
true,
|
|
439
|
+
["encrypt", "decrypt"]
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
__name(importAesKey, "importAesKey");
|
|
443
|
+
async function encryptBytes(msg, key, opts) {
|
|
444
|
+
const data = (0, import_util.normalizeUnicodeToBuf)(msg, opts?.charsize ?? import_constants.DEFAULT_CHAR_SIZE);
|
|
445
|
+
const importedKey = typeof key === "string" ? await (0, import_util.importKey)(key, opts) : key;
|
|
446
|
+
const iv = opts?.iv || (0, import_util.randomBuf)(import_constants.IV_LENGTH);
|
|
447
|
+
const cipherBuf = await import_one_webcrypto.webcrypto.subtle.encrypt({
|
|
448
|
+
name: import_constants.AES_GCM,
|
|
449
|
+
iv
|
|
450
|
+
}, importedKey, data);
|
|
451
|
+
return (0, import_util.joinBufs)(iv, cipherBuf);
|
|
452
|
+
}
|
|
453
|
+
__name(encryptBytes, "encryptBytes");
|
|
454
|
+
async function decryptBytes(msg, key, opts) {
|
|
455
|
+
const cipherText = (0, import_util.normalizeBase64ToBuf)(msg);
|
|
456
|
+
const importedKey = typeof key === "string" ? await (0, import_util.importKey)(key, opts) : key;
|
|
457
|
+
const iv = cipherText.slice(0, import_constants.IV_LENGTH);
|
|
458
|
+
const cipherBytes = cipherText.slice(import_constants.IV_LENGTH);
|
|
459
|
+
const msgBuff = await import_one_webcrypto.webcrypto.subtle.decrypt({
|
|
460
|
+
name: import_constants.DEFAULT_SYMM_ALGORITHM,
|
|
461
|
+
iv
|
|
462
|
+
}, importedKey, cipherBytes);
|
|
463
|
+
return msgBuff;
|
|
464
|
+
}
|
|
465
|
+
__name(decryptBytes, "decryptBytes");
|
|
466
|
+
async function encrypt(data, cryptoKey, format, iv) {
|
|
467
|
+
const key = (0, import_util.isCryptoKey)(cryptoKey) ? cryptoKey : await importAesKey(cryptoKey);
|
|
468
|
+
const encrypted = iv ? await import_one_webcrypto.webcrypto.subtle.encrypt({ name: import_constants.AES_GCM, iv }, key, data) : await encryptBytes(data, key);
|
|
469
|
+
if (format && format === "arraybuffer") return encrypted;
|
|
470
|
+
return new Uint8Array(encrypted);
|
|
471
|
+
}
|
|
472
|
+
__name(encrypt, "encrypt");
|
|
473
|
+
async function getDeviceName(did) {
|
|
474
|
+
const hashedUsername = await (0, import_util.sha256)(
|
|
475
|
+
new TextEncoder().encode(did.normalize("NFD"))
|
|
476
|
+
);
|
|
477
|
+
return (0, import_uint8arrays.toString)(hashedUsername, "base32").slice(0, 32);
|
|
478
|
+
}
|
|
479
|
+
__name(getDeviceName, "getDeviceName");
|
|
480
|
+
//# sourceMappingURL=index.cjs.map
|