lib0 0.2.80 → 0.2.81

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,10 +1,17 @@
1
- export { exportKey } from "./common.js";
2
1
  export function encrypt(key: CryptoKey, data: Uint8Array): Promise<Uint8Array>;
3
2
  export function decrypt(key: CryptoKey, data: Uint8Array): PromiseLike<Uint8Array>;
4
- export function importKey(jwk: any, usages?: Usages | undefined, extractable?: boolean | undefined): Promise<CryptoKey>;
3
+ export function importKeyJwk(jwk: any, { usages, extractable }?: {
4
+ usages?: Usages | undefined;
5
+ extractable?: boolean | undefined;
6
+ }): Promise<CryptoKey>;
7
+ export function importKeyRaw(raw: Uint8Array, { usages, extractable }?: {
8
+ usages?: Usages | undefined;
9
+ extractable?: boolean | undefined;
10
+ }): Promise<CryptoKey>;
5
11
  export function deriveKey(secret: Uint8Array | string, salt: Uint8Array | string, { extractable, usages }?: {
6
12
  extractable?: boolean | undefined;
7
13
  usages?: Usages | undefined;
8
14
  }): Promise<CryptoKey>;
9
15
  export type Usages = Array<'encrypt' | 'decrypt'>;
16
+ export { exportKeyJwk, exportKeyRaw } from "./common.js";
10
17
  //# sourceMappingURL=aes-gcm.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"aes-gcm.d.ts","sourceRoot":"","sources":["aes-gcm.js"],"names":[],"mappings":";AAuBO,6BAHI,SAAS,QACT,UAAU,uBAkBpB;AAWM,6BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CAclC;AAOM,+BAJI,GAAG,sFAUb;AAmBM,kCANI,UAAU,GAAC,MAAM,QACjB,UAAU,GAAC,MAAM;IAEF,WAAW;IACZ,MAAM;uBA0B9B;qBA3GY,MAAM,SAAS,GAAC,SAAS,CAAC"}
1
+ {"version":3,"file":"aes-gcm.d.ts","sourceRoot":"","sources":["aes-gcm.js"],"names":[],"mappings":"AAuBO,6BAHI,SAAS,QACT,UAAU,uBAkBpB;AAWM,6BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CAclC;AAaM,kCALI,GAAG;IAEW,MAAM;IACL,WAAW;uBAQpC;AAUM,kCALI,UAAU;IAEI,MAAM;IACL,WAAW;uBAG2D;AAmBzF,kCANI,UAAU,GAAC,MAAM,QACjB,UAAU,GAAC,MAAM;IAEF,WAAW;IACZ,MAAM;uBAsB5B;qBAxHU,MAAM,SAAS,GAAC,SAAS,CAAC"}
package/crypto/aes-gcm.js CHANGED
@@ -6,7 +6,7 @@ import * as encoding from '../encoding.js'
6
6
  import * as decoding from '../decoding.js'
7
7
  import * as webcrypto from 'lib0/webcrypto'
8
8
  import * as string from '../string.js'
9
- export { exportKey } from './common.js'
9
+ export { exportKeyJwk, exportKeyRaw } from './common.js'
10
10
 
11
11
  /**
12
12
  * @typedef {Array<'encrypt'|'decrypt'>} Usages
@@ -62,12 +62,18 @@ export const decrypt = (key, data) => {
62
62
  ).then(data => new Uint8Array(data))
63
63
  }
64
64
 
65
+ const aesAlgDef = {
66
+ name: 'AES-GCM',
67
+ length: 256
68
+ }
69
+
65
70
  /**
66
71
  * @param {any} jwk
67
- * @param {Usages} [usages]
68
- * @param {boolean} [extractable]
72
+ * @param {Object} opts
73
+ * @param {Usages} [opts.usages]
74
+ * @param {boolean} [opts.extractable]
69
75
  */
70
- export const importKey = (jwk, usages, extractable = false) => {
76
+ export const importKeyJwk = (jwk, { usages, extractable = false } = {}) => {
71
77
  if (usages == null) {
72
78
  /* c8 ignore next */
73
79
  usages = jwk.key_ops || defaultUsages
@@ -75,6 +81,17 @@ export const importKey = (jwk, usages, extractable = false) => {
75
81
  return webcrypto.subtle.importKey('jwk', jwk, 'AES-GCM', extractable, /** @type {Usages} */ (usages))
76
82
  }
77
83
 
84
+ /**
85
+ * Only suited for importing public keys.
86
+ *
87
+ * @param {Uint8Array} raw
88
+ * @param {Object} opts
89
+ * @param {Usages} [opts.usages]
90
+ * @param {boolean} [opts.extractable]
91
+ */
92
+ export const importKeyRaw = (raw, { usages = defaultUsages, extractable = false } = {}) =>
93
+ webcrypto.subtle.importKey('raw', raw, aesAlgDef, extractable, /** @type {Usages} */ (usages))
94
+
78
95
  /**
79
96
  * @param {Uint8Array | string} data
80
97
  */
@@ -92,8 +109,8 @@ const toBinary = data => typeof data === 'string' ? string.encodeUtf8(data) : da
92
109
  * @param {boolean} [opts.extractable]
93
110
  * @param {Usages} [opts.usages]
94
111
  */
95
- export const deriveKey = (secret, salt, { extractable = false, usages = defaultUsages } = {}) => {
96
- return webcrypto.subtle.importKey(
112
+ export const deriveKey = (secret, salt, { extractable = false, usages = defaultUsages } = {}) =>
113
+ webcrypto.subtle.importKey(
97
114
  'raw',
98
115
  toBinary(secret),
99
116
  'PBKDF2',
@@ -108,12 +125,8 @@ export const deriveKey = (secret, salt, { extractable = false, usages = defaultU
108
125
  hash: 'SHA-256'
109
126
  },
110
127
  keyMaterial,
111
- {
112
- name: 'AES-GCM',
113
- length: 256
114
- },
128
+ aesAlgDef,
115
129
  extractable,
116
130
  usages
117
131
  )
118
132
  )
119
- }
@@ -1,2 +1,3 @@
1
- export function exportKey(key: CryptoKey): Promise<JsonWebKey>;
1
+ export function exportKeyJwk(key: CryptoKey): Promise<JsonWebKey>;
2
+ export function exportKeyRaw(key: CryptoKey): Promise<Uint8Array>;
2
3
  //# sourceMappingURL=common.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["common.js"],"names":[],"mappings":"AAKO,+BAFI,SAAS,uBAMnB"}
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["common.js"],"names":[],"mappings":"AAKO,kCAFI,SAAS,uBAMnB;AAQM,kCAHI,SAAS,GACR,QAAQ,UAAU,CAAC,CAG0C"}
package/crypto/common.js CHANGED
@@ -3,8 +3,17 @@ import * as webcrypto from 'lib0/webcrypto'
3
3
  /**
4
4
  * @param {CryptoKey} key
5
5
  */
6
- export const exportKey = async key => {
6
+ export const exportKeyJwk = async key => {
7
7
  const jwk = await webcrypto.subtle.exportKey('jwk', key)
8
8
  jwk.key_ops = key.usages
9
9
  return jwk
10
10
  }
11
+
12
+ /**
13
+ * Only suited for exporting public keys.
14
+ *
15
+ * @param {CryptoKey} key
16
+ * @return {Promise<Uint8Array>}
17
+ */
18
+ export const exportKeyRaw = key =>
19
+ webcrypto.subtle.exportKey('raw', key).then(key => new Uint8Array(key))
package/crypto/ecdsa.d.ts CHANGED
@@ -1,13 +1,17 @@
1
- export { exportKey } from "./common.js";
2
1
  export function sign(key: CryptoKey, data: Uint8Array): PromiseLike<Uint8Array>;
3
2
  export function verify(key: CryptoKey, signature: Uint8Array, data: Uint8Array): PromiseLike<boolean>;
4
3
  export function generateKeyPair({ extractable, usages }?: {
5
4
  extractable?: boolean | undefined;
6
5
  usages?: Usages | undefined;
7
6
  }): Promise<CryptoKeyPair>;
8
- export function importKey(jwk: any, { extractable, usages }?: {
7
+ export function importKeyJwk(jwk: any, { extractable, usages }?: {
8
+ extractable?: boolean | undefined;
9
+ usages?: Usages | undefined;
10
+ }): Promise<CryptoKey>;
11
+ export function importKeyRaw(raw: any, { extractable, usages }?: {
9
12
  extractable?: boolean | undefined;
10
13
  usages?: Usages | undefined;
11
14
  }): Promise<CryptoKey>;
12
15
  export type Usages = Array<'sign' | 'verify'>;
16
+ export { exportKeyJwk, exportKeyRaw } from "./common.js";
13
17
  //# sourceMappingURL=ecdsa.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["ecdsa.js"],"names":[],"mappings":";AAyBO,0BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CAWlC;AAYM,4BALI,SAAS,aACT,UAAU,QACV,UAAU,GACT,YAAY,OAAO,CAAC,CAY/B;AAQM;IAHmB,WAAW;IACZ,MAAM;2BAU5B;AAQI,+BALI,GAAG;IAEY,WAAW;IACZ,MAAM;uBAQ9B;qBA9EY,MAAM,MAAM,GAAC,QAAQ,CAAC"}
1
+ {"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["ecdsa.js"],"names":[],"mappings":"AAyBO,0BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CAWlC;AAYM,4BALI,SAAS,aACT,UAAU,QACV,UAAU,GACT,YAAY,OAAO,CAAC,CAY/B;AAQM;IAHmB,WAAW;IACZ,MAAM;2BAU5B;AAQI,kCALI,GAAG;IAEY,WAAW;IACZ,MAAM;uBAQ9B;AAUM,kCALI,GAAG;IAEY,WAAW;IACZ,MAAM;uBAGsE;qBAzFxF,MAAM,MAAM,GAAC,QAAQ,CAAC"}
package/crypto/ecdsa.js CHANGED
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import * as webcrypto from 'lib0/webcrypto'
6
- export { exportKey } from './common.js'
6
+ export { exportKeyJwk, exportKeyRaw } from './common.js'
7
7
 
8
8
  /**
9
9
  * @typedef {Array<'sign'|'verify'>} Usages
@@ -78,10 +78,21 @@ export const generateKeyPair = ({ extractable = false, usages = defaultUsages }
78
78
  * @param {boolean} [opts.extractable]
79
79
  * @param {Usages} [opts.usages]
80
80
  */
81
- export const importKey = (jwk, { extractable = false, usages } = {}) => {
81
+ export const importKeyJwk = (jwk, { extractable = false, usages } = {}) => {
82
82
  if (usages == null) {
83
- /* c8 ignore next */
83
+ /* c8 ignore next 2 */
84
84
  usages = jwk.key_ops || defaultUsages
85
85
  }
86
86
  return webcrypto.subtle.importKey('jwk', jwk, { name: 'ECDSA', namedCurve: 'P-384' }, extractable, /** @type {Usages} */ (usages))
87
87
  }
88
+
89
+ /**
90
+ * Only suited for importing public keys.
91
+ *
92
+ * @param {any} raw
93
+ * @param {Object} opts
94
+ * @param {boolean} [opts.extractable]
95
+ * @param {Usages} [opts.usages]
96
+ */
97
+ export const importKeyRaw = (raw, { extractable = false, usages = defaultUsages } = {}) =>
98
+ webcrypto.subtle.importKey('raw', raw, { name: 'ECDSA', namedCurve: 'P-384' }, extractable, usages)
@@ -1,11 +1,11 @@
1
- export { exportKey } from "./common.js";
1
+ export { exportKeyJwk } from "./common.js";
2
2
  export function encrypt(key: CryptoKey, data: Uint8Array): PromiseLike<Uint8Array>;
3
3
  export function decrypt(key: CryptoKey, data: Uint8Array): PromiseLike<Uint8Array>;
4
4
  export function generateKeyPair({ extractable, usages }?: {
5
5
  extractable?: boolean | undefined;
6
6
  usages?: Usages | undefined;
7
7
  }): Promise<CryptoKeyPair>;
8
- export function importKey(jwk: any, { extractable, usages }?: {
8
+ export function importKeyJwk(jwk: any, { extractable, usages }?: {
9
9
  extractable?: boolean | undefined;
10
10
  usages?: Usages | undefined;
11
11
  }): Promise<CryptoKey>;
@@ -1 +1 @@
1
- {"version":3,"file":"rsa-oaep.d.ts","sourceRoot":"","sources":["rsa-oaep.js"],"names":[],"mappings":";AAuBO,6BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CASC;AAW7B,6BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CASG;AAQ/B;IAJmB,WAAW;IACZ,MAAM;IACnB,QAAQ,aAAa,CAAC,CAY/B;AAQI,+BALI,GAAG;IAEY,WAAW;IACZ,MAAM;uBAQ9B;qBAxEY,MAAM,SAAS,GAAC,SAAS,CAAC"}
1
+ {"version":3,"file":"rsa-oaep.d.ts","sourceRoot":"","sources":["rsa-oaep.js"],"names":[],"mappings":";AAuBO,6BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CASC;AAW7B,6BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CASG;AAQ/B;IAJmB,WAAW;IACZ,MAAM;IACnB,QAAQ,aAAa,CAAC,CAY/B;AAQI,kCALI,GAAG;IAEY,WAAW;IACZ,MAAM;uBAQ9B;qBAxEY,MAAM,SAAS,GAAC,SAAS,CAAC"}
@@ -3,7 +3,7 @@
3
3
  */
4
4
 
5
5
  import * as webcrypto from 'lib0/webcrypto'
6
- export { exportKey } from './common.js'
6
+ export { exportKeyJwk } from './common.js'
7
7
 
8
8
  /**
9
9
  * @typedef {Array<'encrypt'|'decrypt'>} Usages
@@ -72,7 +72,7 @@ export const generateKeyPair = ({ extractable = false, usages = defaultUsages }
72
72
  * @param {boolean} [opts.extractable]
73
73
  * @param {Usages} [opts.usages]
74
74
  */
75
- export const importKey = (jwk, { extractable = false, usages } = {}) => {
75
+ export const importKeyJwk = (jwk, { extractable = false, usages } = {}) => {
76
76
  if (usages == null) {
77
77
  /* c8 ignore next */
78
78
  usages = jwk.key_ops || defaultUsages
@@ -1 +1 @@
1
- {"version":3,"file":"crypto.test.d.ts","sourceRoot":"","sources":["crypto.test.js"],"names":[],"mappings":"AAUO,mCAFI,EAAE,QAAQ,iBAoCpB;AAKM,0CAFI,EAAE,QAAQ,iBA8BpB;AAKM,qCAFI,EAAE,QAAQ,iBAkCpB;AAKM,8CAFI,EAAE,QAAQ,iBAwCpB;AAKM,iDAFI,EAAE,QAAQ,iBA0EpB;AAKM,gCAFI,EAAE,QAAQ,iBAapB;mBAvPkB,cAAc"}
1
+ {"version":3,"file":"crypto.test.d.ts","sourceRoot":"","sources":["crypto.test.js"],"names":[],"mappings":"AAUO,mCAFI,EAAE,QAAQ,iBAoCpB;AAKM,0CAFI,EAAE,QAAQ,iBA8BpB;AAKM,qCAFI,EAAE,QAAQ,iBAgDpB;AAKM,8CAFI,EAAE,QAAQ,iBAwCpB;AAKM,iDAFI,EAAE,QAAQ,iBA0EpB;AAKM,gCAFI,EAAE,QAAQ,iBAapB;mBArQkB,cAAc"}
package/dist/aes-gcm.cjs CHANGED
@@ -97,12 +97,18 @@ const decrypt = (key, data) => {
97
97
  ).then(data => new Uint8Array(data))
98
98
  };
99
99
 
100
+ const aesAlgDef = {
101
+ name: 'AES-GCM',
102
+ length: 256
103
+ };
104
+
100
105
  /**
101
106
  * @param {any} jwk
102
- * @param {Usages} [usages]
103
- * @param {boolean} [extractable]
107
+ * @param {Object} opts
108
+ * @param {Usages} [opts.usages]
109
+ * @param {boolean} [opts.extractable]
104
110
  */
105
- const importKey = (jwk, usages, extractable = false) => {
111
+ const importKeyJwk = (jwk, { usages, extractable = false } = {}) => {
106
112
  if (usages == null) {
107
113
  /* c8 ignore next */
108
114
  usages = jwk.key_ops || defaultUsages;
@@ -110,6 +116,17 @@ const importKey = (jwk, usages, extractable = false) => {
110
116
  return webcrypto__namespace.subtle.importKey('jwk', jwk, 'AES-GCM', extractable, /** @type {Usages} */ (usages))
111
117
  };
112
118
 
119
+ /**
120
+ * Only suited for importing public keys.
121
+ *
122
+ * @param {Uint8Array} raw
123
+ * @param {Object} opts
124
+ * @param {Usages} [opts.usages]
125
+ * @param {boolean} [opts.extractable]
126
+ */
127
+ const importKeyRaw = (raw, { usages = defaultUsages, extractable = false } = {}) =>
128
+ webcrypto__namespace.subtle.importKey('raw', raw, aesAlgDef, extractable, /** @type {Usages} */ (usages));
129
+
113
130
  /**
114
131
  * @param {Uint8Array | string} data
115
132
  */
@@ -127,8 +144,8 @@ const toBinary = data => typeof data === 'string' ? string.encodeUtf8(data) : da
127
144
  * @param {boolean} [opts.extractable]
128
145
  * @param {Usages} [opts.usages]
129
146
  */
130
- const deriveKey = (secret, salt, { extractable = false, usages = defaultUsages } = {}) => {
131
- return webcrypto__namespace.subtle.importKey(
147
+ const deriveKey = (secret, salt, { extractable = false, usages = defaultUsages } = {}) =>
148
+ webcrypto__namespace.subtle.importKey(
132
149
  'raw',
133
150
  toBinary(secret),
134
151
  'PBKDF2',
@@ -143,19 +160,17 @@ const deriveKey = (secret, salt, { extractable = false, usages = defaultUsages }
143
160
  hash: 'SHA-256'
144
161
  },
145
162
  keyMaterial,
146
- {
147
- name: 'AES-GCM',
148
- length: 256
149
- },
163
+ aesAlgDef,
150
164
  extractable,
151
165
  usages
152
166
  )
153
- )
154
- };
167
+ );
155
168
 
156
- exports.exportKey = common.exportKey;
169
+ exports.exportKeyJwk = common.exportKeyJwk;
170
+ exports.exportKeyRaw = common.exportKeyRaw;
157
171
  exports.decrypt = decrypt;
158
172
  exports.deriveKey = deriveKey;
159
173
  exports.encrypt = encrypt;
160
- exports.importKey = importKey;
174
+ exports.importKeyJwk = importKeyJwk;
175
+ exports.importKeyRaw = importKeyRaw;
161
176
  //# sourceMappingURL=aes-gcm.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"aes-gcm.cjs","sources":["../crypto/aes-gcm.js"],"sourcesContent":["/**\n * AES-GCM is a symmetric key for encryption\n */\n\nimport * as encoding from '../encoding.js'\nimport * as decoding from '../decoding.js'\nimport * as webcrypto from 'lib0/webcrypto'\nimport * as string from '../string.js'\nexport { exportKey } from './common.js'\n\n/**\n * @typedef {Array<'encrypt'|'decrypt'>} Usages\n */\n\n/**\n * @type {Usages}\n */\nconst defaultUsages = ['encrypt', 'decrypt']\n\n/**\n * @param {CryptoKey} key\n * @param {Uint8Array} data\n */\nexport const encrypt = (key, data) => {\n const iv = webcrypto.getRandomValues(new Uint8Array(16)) // 92bit is enough. 128bit is recommended if space is not an issue.\n return webcrypto.subtle.encrypt(\n {\n name: 'AES-GCM',\n iv\n },\n key,\n data\n ).then(cipher => {\n const encryptedDataEncoder = encoding.createEncoder()\n // iv may be sent in the clear to the other peers\n encoding.writeUint8Array(encryptedDataEncoder, iv)\n encoding.writeVarUint8Array(encryptedDataEncoder, new Uint8Array(cipher))\n return encoding.toUint8Array(encryptedDataEncoder)\n })\n}\n\n/**\n * @experimental The API is not final!\n *\n * Decrypt some data using AES-GCM method.\n *\n * @param {CryptoKey} key\n * @param {Uint8Array} data\n * @return {PromiseLike<Uint8Array>} decrypted buffer\n */\nexport const decrypt = (key, data) => {\n const dataDecoder = decoding.createDecoder(data)\n const iv = decoding.readUint8Array(dataDecoder, 16)\n const cipher = decoding.readVarUint8Array(dataDecoder)\n return webcrypto.subtle.decrypt(\n {\n name: 'AES-GCM',\n iv\n },\n key,\n cipher\n ).then(data => new Uint8Array(data))\n}\n\n/**\n * @param {any} jwk\n * @param {Usages} [usages]\n * @param {boolean} [extractable]\n */\nexport const importKey = (jwk, usages, extractable = false) => {\n if (usages == null) {\n /* c8 ignore next */\n usages = jwk.key_ops || defaultUsages\n }\n return webcrypto.subtle.importKey('jwk', jwk, 'AES-GCM', extractable, /** @type {Usages} */ (usages))\n}\n\n/**\n * @param {Uint8Array | string} data\n */\n/* c8 ignore next */\nconst toBinary = data => typeof data === 'string' ? string.encodeUtf8(data) : data\n\n/**\n * @experimental The API is not final!\n *\n * Derive an symmetric key using the Password-Based-Key-Derivation-Function-2.\n *\n * @param {Uint8Array|string} secret\n * @param {Uint8Array|string} salt\n * @param {Object} opts\n * @param {boolean} [opts.extractable]\n * @param {Usages} [opts.usages]\n */\nexport const deriveKey = (secret, salt, { extractable = false, usages = defaultUsages } = {}) => {\n return webcrypto.subtle.importKey(\n 'raw',\n toBinary(secret),\n 'PBKDF2',\n false,\n ['deriveKey']\n ).then(keyMaterial =>\n webcrypto.subtle.deriveKey(\n {\n name: 'PBKDF2',\n salt: toBinary(salt), // NIST recommends at least 64 bits\n iterations: 600000, // OWASP recommends 600k iterations\n hash: 'SHA-256'\n },\n keyMaterial,\n {\n name: 'AES-GCM',\n length: 256\n },\n extractable,\n usages\n )\n )\n}\n"],"names":["webcrypto","encoding.createEncoder","encoding.writeUint8Array","encoding.writeVarUint8Array","encoding.toUint8Array","decoding.createDecoder","decoding.readUint8Array","decoding.readVarUint8Array","string.encodeUtf8"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,aAAa,GAAG,CAAC,SAAS,EAAE,SAAS,EAAC;AAC5C;AACA;AACA;AACA;AACA;AACY,MAAC,OAAO,GAAG,CAAC,GAAG,EAAE,IAAI,KAAK;AACtC,EAAE,MAAM,EAAE,GAAGA,oBAAS,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,EAAC;AAC1D,EAAE,OAAOA,oBAAS,CAAC,MAAM,CAAC,OA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GAAG,EAAE,SAAS,EAAE,WAAW,yBAAyB,MAAM,EAAE;AACvG,EAAC;AACD;AACA;AACA;AACA;AACA;AACA,MAAM,QAAQ,GAAG,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,GAAGQ,iBAAiB,CAAC,IAAI,CAAC,GAAG,KAAI;AAClF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,SAAS,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,WAAW,GAAG,KAAK,EAAE,MAAM,GAAG,aAAa,EAAE,GAAG,EAAE,KAAK;AACjG,EAAE,OAAOR,oBAAS,CAAC,MAAM,CAAC,SAAS;AACnC,IAAI,KAAK;AACT,IAAI,QAAQ,CAAC,MAAM,CAAC;AACpB,IAAI,QAAQ;AACZ,IAAI,KAAK;AACT,IAAI,CAAC,WAAW,CAAC;AACjB,GAAG,CAAC,IAAI,CAAC,WAAW;AACpB,IAAIA,oBAAS,CAAC,MAAM,CAAC,SAAS;AAC9B,MAAM;AACN,QAAQ,IAAI,EAAE,QAAQ;AACtB,QAAQ,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC;AAC5B,QAAQ,UAAU,EAAE,MAAM;AAC1B,QAAQ,IAAI,EAAE,SAAS;AACvB,OAAO;AACP,MAAM,WAAW;AACjB,MAAM;AACN,QAAQ,IAAI,EAAE,SAAS;AACvB,QAAQ,MAAM,EAAE,GAAG;AACnB,OAAO;AACP,MAAM,WAAW;AACjB,MAAM,MAAM;AACZ,KAAK;AACL,GAAG;AACH;;;;;;;;"}
1
+ {"version":3,"file":"aes-gcm.cjs","sources":["../crypto/aes-gcm.js"],"sourcesContent":["/**\n * AES-GCM is a symmetric key for encryption\n */\n\nimport * as encoding from '../encoding.js'\nimport * as decoding from '../decoding.js'\nimport * as webcrypto from 'lib0/webcrypto'\nimport * as string from '../string.js'\nexport { exportKeyJwk, exportKeyRaw } from './common.js'\n\n/**\n * @typedef {Array<'encrypt'|'decrypt'>} Usages\n */\n\n/**\n * @type {Usages}\n */\nconst defaultUsages = ['encrypt', 'decrypt']\n\n/**\n * @param {CryptoKey} key\n * @param {Uint8Array} data\n */\nexport const encrypt = (key, data) => {\n const iv = webcrypto.getRandomValues(new Uint8Array(16)) // 92bit is enough. 128bit is recommended if space is not an issue.\n return webcrypto.subtle.encrypt(\n {\n name: 'AES-GCM',\n iv\n },\n key,\n data\n ).then(cipher => {\n const encryptedDataEncoder = encoding.createEncoder()\n // iv may be sent in the clear to the other peers\n encoding.writeUint8Array(encryptedDataEncoder, iv)\n encoding.writeVarUint8Array(encryptedDataEncoder, new Uint8Array(cipher))\n return encoding.toUint8Array(encryptedDataEncoder)\n })\n}\n\n/**\n * @experimental The API is not final!\n *\n * Decrypt some data using AES-GCM method.\n *\n * @param {CryptoKey} key\n * @param {Uint8Array} data\n * @return {PromiseLike<Uint8Array>} decrypted buffer\n */\nexport const decrypt = (key, data) => {\n const dataDecoder = decoding.createDecoder(data)\n const iv = decoding.readUint8Array(dataDecoder, 16)\n const cipher = decoding.readVarUint8Array(dataDecoder)\n return webcrypto.subtle.decrypt(\n {\n name: 'AES-GCM',\n iv\n },\n key,\n cipher\n ).then(data => new Uint8Array(data))\n}\n\nconst aesAlgDef = {\n name: 'AES-GCM',\n length: 256\n}\n\n/**\n * @param {any} jwk\n * @param {Object} opts\n * @param {Usages} [opts.usages]\n * @param {boolean} [opts.extractable]\n */\nexport const importKeyJwk = (jwk, { usages, extractable = false } = {}) => {\n if (usages == null) {\n /* c8 ignore next */\n usages = jwk.key_ops || defaultUsages\n }\n return webcrypto.subtle.importKey('jwk', jwk, 'AES-GCM', extractable, /** @type {Usages} */ (usages))\n}\n\n/**\n * Only suited for importing public keys.\n *\n * @param {Uint8Array} raw\n * @param {Object} opts\n * @param {Usages} [opts.usages]\n * @param {boolean} [opts.extractable]\n */\nexport const importKeyRaw = (raw, { usages = defaultUsages, extractable = false } = {}) =>\n webcrypto.subtle.importKey('raw', raw, aesAlgDef, extractable, /** @type {Usages} */ (usages))\n\n/**\n * @param {Uint8Array | string} data\n */\n/* c8 ignore next */\nconst toBinary = data => typeof data === 'string' ? string.encodeUtf8(data) : data\n\n/**\n * @experimental The API is not final!\n *\n * Derive an symmetric key using the Password-Based-Key-Derivation-Function-2.\n *\n * @param {Uint8Array|string} secret\n * @param {Uint8Array|string} salt\n * @param {Object} opts\n * @param {boolean} [opts.extractable]\n * @param {Usages} [opts.usages]\n */\nexport const deriveKey = (secret, salt, { extractable = false, usages = defaultUsages } = {}) =>\n webcrypto.subtle.importKey(\n 'raw',\n toBinary(secret),\n 'PBKDF2',\n false,\n ['deriveKey']\n ).then(keyMaterial =>\n webcrypto.subtle.deriveKey(\n {\n name: 'PBKDF2',\n salt: toBinary(salt), // NIST recommends at least 64 bits\n iterations: 600000, // OWASP recommends 600k iterations\n hash: 'SHA-256'\n },\n keyMaterial,\n aesAlgDef,\n extractable,\n usages\n )\n )\n"],"names":["webcrypto","encoding.createEncoder","encoding.writeUint8Array","encoding.writeVarUint8Array","encoding.toUint8Array","decoding.createDecoder","decoding.readUint8Array","decoding.readVarUint8Array","string.encodeUtf8"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,aAAa,GAAG,CAAC,SAAS,EAAE,SAAS,EAAC;AAC5C;AACA;AACA;AACA;AACA;AACY,MAAC,OAAO,GAAG,CAAC,GAAG,EAAE,IAAI,KAAK;AACtC,EAAE,MAAM,EAAE,GAAGA,oBAAS,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,EAAC;AAC1D,EAAE,OAAOA,oBAAS,CAAC,MAAM,CAAC,OAAO;AACjC,IAAI;AACJ,MAAM,IAAI,EAAE,SAAS;AACrB,MAAM,EAAE;AACR,KAAK;AACL,IAAI,GAAG;AACP,IAAI,IAAI;AACR,GAAG,CAAC,IAAI,CAAC,MA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  /**
28
28
  * @param {CryptoKey} key
29
29
  */
30
- const exportKey = async key => {
30
+ const exportKeyJwk = async key => {
31
31
  const jwk = await webcrypto__namespace.subtle.exportKey('jwk', key);
32
32
  jwk.key_ops = key.usages;
33
33
  return jwk
34
34
  };
35
35
 
36
- exports.exportKey = exportKey;
36
+ /**
37
+ * Only suited for exporting public keys.
38
+ *
39
+ * @param {CryptoKey} key
40
+ * @return {Promise<Uint8Array>}
41
+ */
42
+ const exportKeyRaw = key =>
43
+ webcrypto__namespace.subtle.exportKey('raw', key).then(key => new Uint8Array(key));
44
+
45
+ exports.exportKeyJwk = exportKeyJwk;
46
+ exports.exportKeyRaw = exportKeyRaw;
37
47
  //# sourceMappingURL=common.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.cjs","sources":["../crypto/common.js"],"sourcesContent":["import * as webcrypto from 'lib0/webcrypto'\n\n/**\n * @param {CryptoKey} key\n */\nexport const exportKey = async key => {\n const jwk = await webcrypto.subtle.exportKey('jwk', key)\n jwk.key_ops = key.usages\n return jwk\n}\n"],"names":["webcrypto"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;AACA;AACA;AACY,MAAC,SAAS,GAAG,MAAM,GAAG,IAAI;AACtC,EAAE,MAAM,GAAG,GAAG,MAAMA,oBAAS,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,EAAC;AAC1D,EAAE,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAM;AAC1B,EAAE,OAAO,GAAG;AACZ;;;;"}
1
+ {"version":3,"file":"common.cjs","sources":["../crypto/common.js"],"sourcesContent":["import * as webcrypto from 'lib0/webcrypto'\n\n/**\n * @param {CryptoKey} key\n */\nexport const exportKeyJwk = async key => {\n const jwk = await webcrypto.subtle.exportKey('jwk', key)\n jwk.key_ops = key.usages\n return jwk\n}\n\n/**\n * Only suited for exporting public keys.\n *\n * @param {CryptoKey} key\n * @return {Promise<Uint8Array>}\n */\nexport const exportKeyRaw = key =>\n webcrypto.subtle.exportKey('raw', key).then(key => new Uint8Array(key))\n"],"names":["webcrypto"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;AACA;AACA;AACY,MAAC,YAAY,GAAG,MAAM,GAAG,IAAI;AACzC,EAAE,MAAM,GAAG,GAAG,MAAMA,oBAAS,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,EAAC;AAC1D,EAAE,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAM;AAC1B,EAAE,OAAO,GAAG;AACZ,EAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,YAAY,GAAG,GAAG;AAC/B,EAAEA,oBAAS,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,UAAU,CAAC,GAAG,CAAC;;;;;"}
@@ -1,10 +1,17 @@
1
- export { exportKey } from "./common.js";
2
1
  export function encrypt(key: CryptoKey, data: Uint8Array): Promise<Uint8Array>;
3
2
  export function decrypt(key: CryptoKey, data: Uint8Array): PromiseLike<Uint8Array>;
4
- export function importKey(jwk: any, usages?: Usages | undefined, extractable?: boolean | undefined): Promise<CryptoKey>;
3
+ export function importKeyJwk(jwk: any, { usages, extractable }?: {
4
+ usages?: Usages | undefined;
5
+ extractable?: boolean | undefined;
6
+ }): Promise<CryptoKey>;
7
+ export function importKeyRaw(raw: Uint8Array, { usages, extractable }?: {
8
+ usages?: Usages | undefined;
9
+ extractable?: boolean | undefined;
10
+ }): Promise<CryptoKey>;
5
11
  export function deriveKey(secret: Uint8Array | string, salt: Uint8Array | string, { extractable, usages }?: {
6
12
  extractable?: boolean | undefined;
7
13
  usages?: Usages | undefined;
8
14
  }): Promise<CryptoKey>;
9
15
  export type Usages = Array<'encrypt' | 'decrypt'>;
16
+ export { exportKeyJwk, exportKeyRaw } from "./common.js";
10
17
  //# sourceMappingURL=aes-gcm.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"aes-gcm.d.ts","sourceRoot":"","sources":["../../crypto/aes-gcm.js"],"names":[],"mappings":";AAuBO,6BAHI,SAAS,QACT,UAAU,uBAkBpB;AAWM,6BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CAclC;AAOM,+BAJI,GAAG,sFAUb;AAmBM,kCANI,UAAU,GAAC,MAAM,QACjB,UAAU,GAAC,MAAM;IAEF,WAAW;IACZ,MAAM;uBA0B9B;qBA3GY,MAAM,SAAS,GAAC,SAAS,CAAC"}
1
+ {"version":3,"file":"aes-gcm.d.ts","sourceRoot":"","sources":["../../crypto/aes-gcm.js"],"names":[],"mappings":"AAuBO,6BAHI,SAAS,QACT,UAAU,uBAkBpB;AAWM,6BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CAclC;AAaM,kCALI,GAAG;IAEW,MAAM;IACL,WAAW;uBAQpC;AAUM,kCALI,UAAU;IAEI,MAAM;IACL,WAAW;uBAG2D;AAmBzF,kCANI,UAAU,GAAC,MAAM,QACjB,UAAU,GAAC,MAAM;IAEF,WAAW;IACZ,MAAM;uBAsB5B;qBAxHU,MAAM,SAAS,GAAC,SAAS,CAAC"}
@@ -1,2 +1,3 @@
1
- export function exportKey(key: CryptoKey): Promise<JsonWebKey>;
1
+ export function exportKeyJwk(key: CryptoKey): Promise<JsonWebKey>;
2
+ export function exportKeyRaw(key: CryptoKey): Promise<Uint8Array>;
2
3
  //# sourceMappingURL=common.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../crypto/common.js"],"names":[],"mappings":"AAKO,+BAFI,SAAS,uBAMnB"}
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../crypto/common.js"],"names":[],"mappings":"AAKO,kCAFI,SAAS,uBAMnB;AAQM,kCAHI,SAAS,GACR,QAAQ,UAAU,CAAC,CAG0C"}
@@ -1,13 +1,17 @@
1
- export { exportKey } from "./common.js";
2
1
  export function sign(key: CryptoKey, data: Uint8Array): PromiseLike<Uint8Array>;
3
2
  export function verify(key: CryptoKey, signature: Uint8Array, data: Uint8Array): PromiseLike<boolean>;
4
3
  export function generateKeyPair({ extractable, usages }?: {
5
4
  extractable?: boolean | undefined;
6
5
  usages?: Usages | undefined;
7
6
  }): Promise<CryptoKeyPair>;
8
- export function importKey(jwk: any, { extractable, usages }?: {
7
+ export function importKeyJwk(jwk: any, { extractable, usages }?: {
8
+ extractable?: boolean | undefined;
9
+ usages?: Usages | undefined;
10
+ }): Promise<CryptoKey>;
11
+ export function importKeyRaw(raw: any, { extractable, usages }?: {
9
12
  extractable?: boolean | undefined;
10
13
  usages?: Usages | undefined;
11
14
  }): Promise<CryptoKey>;
12
15
  export type Usages = Array<'sign' | 'verify'>;
16
+ export { exportKeyJwk, exportKeyRaw } from "./common.js";
13
17
  //# sourceMappingURL=ecdsa.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["../../crypto/ecdsa.js"],"names":[],"mappings":";AAyBO,0BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CAWlC;AAYM,4BALI,SAAS,aACT,UAAU,QACV,UAAU,GACT,YAAY,OAAO,CAAC,CAY/B;AAQM;IAHmB,WAAW;IACZ,MAAM;2BAU5B;AAQI,+BALI,GAAG;IAEY,WAAW;IACZ,MAAM;uBAQ9B;qBA9EY,MAAM,MAAM,GAAC,QAAQ,CAAC"}
1
+ {"version":3,"file":"ecdsa.d.ts","sourceRoot":"","sources":["../../crypto/ecdsa.js"],"names":[],"mappings":"AAyBO,0BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CAWlC;AAYM,4BALI,SAAS,aACT,UAAU,QACV,UAAU,GACT,YAAY,OAAO,CAAC,CAY/B;AAQM;IAHmB,WAAW;IACZ,MAAM;2BAU5B;AAQI,kCALI,GAAG;IAEY,WAAW;IACZ,MAAM;uBAQ9B;AAUM,kCALI,GAAG;IAEY,WAAW;IACZ,MAAM;uBAGsE;qBAzFxF,MAAM,MAAM,GAAC,QAAQ,CAAC"}
@@ -1,11 +1,11 @@
1
- export { exportKey } from "./common.js";
1
+ export { exportKeyJwk } from "./common.js";
2
2
  export function encrypt(key: CryptoKey, data: Uint8Array): PromiseLike<Uint8Array>;
3
3
  export function decrypt(key: CryptoKey, data: Uint8Array): PromiseLike<Uint8Array>;
4
4
  export function generateKeyPair({ extractable, usages }?: {
5
5
  extractable?: boolean | undefined;
6
6
  usages?: Usages | undefined;
7
7
  }): Promise<CryptoKeyPair>;
8
- export function importKey(jwk: any, { extractable, usages }?: {
8
+ export function importKeyJwk(jwk: any, { extractable, usages }?: {
9
9
  extractable?: boolean | undefined;
10
10
  usages?: Usages | undefined;
11
11
  }): Promise<CryptoKey>;
@@ -1 +1 @@
1
- {"version":3,"file":"rsa-oaep.d.ts","sourceRoot":"","sources":["../../crypto/rsa-oaep.js"],"names":[],"mappings":";AAuBO,6BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CASC;AAW7B,6BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CASG;AAQ/B;IAJmB,WAAW;IACZ,MAAM;IACnB,QAAQ,aAAa,CAAC,CAY/B;AAQI,+BALI,GAAG;IAEY,WAAW;IACZ,MAAM;uBAQ9B;qBAxEY,MAAM,SAAS,GAAC,SAAS,CAAC"}
1
+ {"version":3,"file":"rsa-oaep.d.ts","sourceRoot":"","sources":["../../crypto/rsa-oaep.js"],"names":[],"mappings":";AAuBO,6BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CASC;AAW7B,6BAJI,SAAS,QACT,UAAU,GACT,YAAY,UAAU,CAAC,CASG;AAQ/B;IAJmB,WAAW;IACZ,MAAM;IACnB,QAAQ,aAAa,CAAC,CAY/B;AAQI,kCALI,GAAG;IAEY,WAAW;IACZ,MAAM;uBAQ9B;qBAxEY,MAAM,SAAS,GAAC,SAAS,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"crypto.test.d.ts","sourceRoot":"","sources":["../crypto.test.js"],"names":[],"mappings":"AAUO,mCAFI,EAAE,QAAQ,iBAoCpB;AAKM,0CAFI,EAAE,QAAQ,iBA8BpB;AAKM,qCAFI,EAAE,QAAQ,iBAkCpB;AAKM,8CAFI,EAAE,QAAQ,iBAwCpB;AAKM,iDAFI,EAAE,QAAQ,iBA0EpB;AAKM,gCAFI,EAAE,QAAQ,iBAapB;mBAvPkB,cAAc"}
1
+ {"version":3,"file":"crypto.test.d.ts","sourceRoot":"","sources":["../crypto.test.js"],"names":[],"mappings":"AAUO,mCAFI,EAAE,QAAQ,iBAoCpB;AAKM,0CAFI,EAAE,QAAQ,iBA8BpB;AAKM,qCAFI,EAAE,QAAQ,iBAgDpB;AAKM,8CAFI,EAAE,QAAQ,iBAwCpB;AAKM,iDAFI,EAAE,QAAQ,iBA0EpB;AAKM,gCAFI,EAAE,QAAQ,iBAapB;mBArQkB,cAAc"}
package/dist/ecdsa.cjs CHANGED
@@ -102,17 +102,30 @@ const generateKeyPair = ({ extractable = false, usages = defaultUsages } = {}) =
102
102
  * @param {boolean} [opts.extractable]
103
103
  * @param {Usages} [opts.usages]
104
104
  */
105
- const importKey = (jwk, { extractable = false, usages } = {}) => {
105
+ const importKeyJwk = (jwk, { extractable = false, usages } = {}) => {
106
106
  if (usages == null) {
107
- /* c8 ignore next */
107
+ /* c8 ignore next 2 */
108
108
  usages = jwk.key_ops || defaultUsages;
109
109
  }
110
110
  return webcrypto__namespace.subtle.importKey('jwk', jwk, { name: 'ECDSA', namedCurve: 'P-384' }, extractable, /** @type {Usages} */ (usages))
111
111
  };
112
112
 
113
- exports.exportKey = common.exportKey;
113
+ /**
114
+ * Only suited for importing public keys.
115
+ *
116
+ * @param {any} raw
117
+ * @param {Object} opts
118
+ * @param {boolean} [opts.extractable]
119
+ * @param {Usages} [opts.usages]
120
+ */
121
+ const importKeyRaw = (raw, { extractable = false, usages = defaultUsages } = {}) =>
122
+ webcrypto__namespace.subtle.importKey('raw', raw, { name: 'ECDSA', namedCurve: 'P-384' }, extractable, usages);
123
+
124
+ exports.exportKeyJwk = common.exportKeyJwk;
125
+ exports.exportKeyRaw = common.exportKeyRaw;
114
126
  exports.generateKeyPair = generateKeyPair;
115
- exports.importKey = importKey;
127
+ exports.importKeyJwk = importKeyJwk;
128
+ exports.importKeyRaw = importKeyRaw;
116
129
  exports.sign = sign;
117
130
  exports.verify = verify;
118
131
  //# sourceMappingURL=ecdsa.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ecdsa.cjs","sources":["../crypto/ecdsa.js"],"sourcesContent":["/**\n * ECDSA is an asymmetric key for signing\n */\n\nimport * as webcrypto from 'lib0/webcrypto'\nexport { exportKey } from './common.js'\n\n/**\n * @typedef {Array<'sign'|'verify'>} Usages\n */\n\n/**\n * @type {Usages}\n */\nconst defaultUsages = ['sign', 'verify']\n\n/**\n * @experimental The API is not final!\n *\n * Sign a message\n *\n * @param {CryptoKey} key\n * @param {Uint8Array} data\n * @return {PromiseLike<Uint8Array>} signature\n */\nexport const sign = (key, data) => {\n return webcrypto.subtle.sign(\n {\n name: 'ECDSA',\n hash: { name: 'SHA-384' }\n },\n key,\n data\n ).then(signature => new Uint8Array(signature))\n}\n\n/**\n * @experimental The API is not final!\n *\n * Sign a message\n *\n * @param {CryptoKey} key\n * @param {Uint8Array} signature\n * @param {Uint8Array} data\n * @return {PromiseLike<boolean>} signature\n */\nexport const verify = (key, signature, data) => {\n return webcrypto.subtle.verify(\n {\n name: 'ECDSA',\n hash: { name: 'SHA-384' }\n },\n key,\n signature,\n data\n )\n}\n\n/* c8 ignore next */\n/**\n * @param {Object} opts\n * @param {boolean} [opts.extractable]\n * @param {Usages} [opts.usages]\n */\nexport const generateKeyPair = ({ extractable = false, usages = defaultUsages } = {}) =>\n webcrypto.subtle.generateKey(\n {\n name: 'ECDSA',\n namedCurve: 'P-384'\n },\n extractable,\n usages\n )\n\n/**\n * @param {any} jwk\n * @param {Object} opts\n * @param {boolean} [opts.extractable]\n * @param {Usages} [opts.usages]\n */\nexport const importKey = (jwk, { extractable = false, usages } = {}) => {\n if (usages == null) {\n /* c8 ignore next */\n usages = jwk.key_ops || defaultUsages\n }\n return webcrypto.subtle.importKey('jwk', jwk, { name: 'ECDSA', namedCurve: 'P-384' }, extractable, /** @type {Usages} */ (usages))\n}\n"],"names":["webcrypto"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAC;AACxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,IAAI,GAAG,CAAC,GAAG,EAAE,IAAI,KAAK;AACnC,EAAE,OAAOA,oBAAS,CAAC,MAAM,CAAC,IAAI;AAC9B,IAAI;AACJ,MAAM,IAAI,EAAE,OAAO;AACnB,MAAM,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;AAC/B,KAAK;AACL,IAAI,GAAG;AACP,IAAI,IAAI;AACR,GAAG,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC;AAChD,EAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,KAAK;AAChD,EAAE,OAAOA,oBAAS,CAAC,MAAM,CAAC,MAAM;AAChC,IAAI;AACJ,MAAM,IAAI,EAAE,OAAO;AACnB,MAAM,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;AAC/B,KAAK;AACL,IAAI,GAAG;AACP,IAAI,SAAS;AACb,IAAI,IAAI;AACR,GAAG;AACH,EAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,eAAe,GAAG,CAAC,EAAE,WAAW,GAAG,KAAK,EAAE,MAAM,GAAG,aAAa,EAAE,GAAG,EAAE;AACpF,EAAEA,oBAAS,CAAC,MAAM,CAAC,WAAW;AAC9B,IAAI;AACJ,MAAM,IAAI,EAAE,OAAO;AACnB,MAAM,UAAU,EAAE,OAAO;AACzB,KAAK;AACL,IAAI,WAAW;AACf,IAAI,MAAM;AACV,IAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,SAAS,GAAG,CAAC,GAAG,EAAE,EAAE,WAAW,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK;AACxE,EAAE,IAAI,MAAM,IAAI,IAAI,EAAE;AACtB;AACA,IAAI,MAAM,GAAG,GAAG,CAAC,OAAO,IAAI,cAAa;AACzC,GAAG;AACH,EAAE,OAAOA,oBAAS,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,WAAW,yBAAyB,MAAM,EAAE;AACpI;;;;;;;;"}
1
+ {"version":3,"file":"ecdsa.cjs","sources":["../crypto/ecdsa.js"],"sourcesContent":["/**\n * ECDSA is an asymmetric key for signing\n */\n\nimport * as webcrypto from 'lib0/webcrypto'\nexport { exportKeyJwk, exportKeyRaw } from './common.js'\n\n/**\n * @typedef {Array<'sign'|'verify'>} Usages\n */\n\n/**\n * @type {Usages}\n */\nconst defaultUsages = ['sign', 'verify']\n\n/**\n * @experimental The API is not final!\n *\n * Sign a message\n *\n * @param {CryptoKey} key\n * @param {Uint8Array} data\n * @return {PromiseLike<Uint8Array>} signature\n */\nexport const sign = (key, data) => {\n return webcrypto.subtle.sign(\n {\n name: 'ECDSA',\n hash: { name: 'SHA-384' }\n },\n key,\n data\n ).then(signature => new Uint8Array(signature))\n}\n\n/**\n * @experimental The API is not final!\n *\n * Sign a message\n *\n * @param {CryptoKey} key\n * @param {Uint8Array} signature\n * @param {Uint8Array} data\n * @return {PromiseLike<boolean>} signature\n */\nexport const verify = (key, signature, data) => {\n return webcrypto.subtle.verify(\n {\n name: 'ECDSA',\n hash: { name: 'SHA-384' }\n },\n key,\n signature,\n data\n )\n}\n\n/* c8 ignore next */\n/**\n * @param {Object} opts\n * @param {boolean} [opts.extractable]\n * @param {Usages} [opts.usages]\n */\nexport const generateKeyPair = ({ extractable = false, usages = defaultUsages } = {}) =>\n webcrypto.subtle.generateKey(\n {\n name: 'ECDSA',\n namedCurve: 'P-384'\n },\n extractable,\n usages\n )\n\n/**\n * @param {any} jwk\n * @param {Object} opts\n * @param {boolean} [opts.extractable]\n * @param {Usages} [opts.usages]\n */\nexport const importKeyJwk = (jwk, { extractable = false, usages } = {}) => {\n if (usages == null) {\n /* c8 ignore next 2 */\n usages = jwk.key_ops || defaultUsages\n }\n return webcrypto.subtle.importKey('jwk', jwk, { name: 'ECDSA', namedCurve: 'P-384' }, extractable, /** @type {Usages} */ (usages))\n}\n\n/**\n * Only suited for importing public keys.\n *\n * @param {any} raw\n * @param {Object} opts\n * @param {boolean} [opts.extractable]\n * @param {Usages} [opts.usages]\n */\nexport const importKeyRaw = (raw, { extractable = false, usages = defaultUsages } = {}) =>\n webcrypto.subtle.importKey('raw', raw, { name: 'ECDSA', namedCurve: 'P-384' }, extractable, usages)\n"],"names":["webcrypto"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAC;AACxC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,IAAI,GAAG,CAAC,GAAG,EAAE,IAAI,KAAK;AACnC,EAAE,OAAOA,oBAAS,CAAC,MAAM,CAAC,IAAI;AAC9B,IAAI;AACJ,MAAM,IAAI,EAAE,OAAO;AACnB,MAAM,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;AAC/B,KAAK;AACL,IAAI,GAAG;AACP,I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C,YAAY,GAAG,CAAC,GAAG,EAAE,EAAE,WAAW,GAAG,KAAK,EAAE,MAAM,GAAG,aAAa,EAAE,GAAG,EAAE;AACtF,EAAEA,oBAAS,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,WAAW,EAAE,MAAM;;;;;;;;;;"}
package/dist/rsa-oaep.cjs CHANGED
@@ -96,7 +96,7 @@ const generateKeyPair = ({ extractable = false, usages = defaultUsages } = {}) =
96
96
  * @param {boolean} [opts.extractable]
97
97
  * @param {Usages} [opts.usages]
98
98
  */
99
- const importKey = (jwk, { extractable = false, usages } = {}) => {
99
+ const importKeyJwk = (jwk, { extractable = false, usages } = {}) => {
100
100
  if (usages == null) {
101
101
  /* c8 ignore next */
102
102
  usages = jwk.key_ops || defaultUsages;
@@ -104,9 +104,9 @@ const importKey = (jwk, { extractable = false, usages } = {}) => {
104
104
  return webcrypto__namespace.subtle.importKey('jwk', jwk, { name: 'RSA-OAEP', hash: 'SHA-256' }, extractable, /** @type {Usages} */ (usages))
105
105
  };
106
106
 
107
- exports.exportKey = common.exportKey;
107
+ exports.exportKeyJwk = common.exportKeyJwk;
108
108
  exports.decrypt = decrypt;
109
109
  exports.encrypt = encrypt;
110
110
  exports.generateKeyPair = generateKeyPair;
111
- exports.importKey = importKey;
111
+ exports.importKeyJwk = importKeyJwk;
112
112
  //# sourceMappingURL=rsa-oaep.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"rsa-oaep.cjs","sources":["../crypto/rsa-oaep.js"],"sourcesContent":["/**\n * RSA-OAEP is an asymmetric keypair used for encryption\n */\n\nimport * as webcrypto from 'lib0/webcrypto'\nexport { exportKey } from './common.js'\n\n/**\n * @typedef {Array<'encrypt'|'decrypt'>} Usages\n */\n\n/**\n * @type {Usages}\n */\nconst defaultUsages = ['encrypt', 'decrypt']\n\n/**\n * Note that the max data size is limited by the size of the RSA key.\n *\n * @param {CryptoKey} key\n * @param {Uint8Array} data\n * @return {PromiseLike<Uint8Array>}\n */\nexport const encrypt = (key, data) =>\n webcrypto.subtle.encrypt(\n {\n name: 'RSA-OAEP'\n },\n key,\n data\n ).then(buf => new Uint8Array(buf))\n\n/**\n * @experimental The API is not final!\n *\n * Decrypt some data using AES-GCM method.\n *\n * @param {CryptoKey} key\n * @param {Uint8Array} data\n * @return {PromiseLike<Uint8Array>} decrypted buffer\n */\nexport const decrypt = (key, data) =>\n webcrypto.subtle.decrypt(\n {\n name: 'RSA-OAEP'\n },\n key,\n data\n ).then(data => new Uint8Array(data))\n\n/**\n * @param {Object} opts\n * @param {boolean} [opts.extractable]\n * @param {Usages} [opts.usages]\n * @return {Promise<CryptoKeyPair>}\n */\nexport const generateKeyPair = ({ extractable = false, usages = defaultUsages } = {}) =>\n webcrypto.subtle.generateKey(\n {\n name: 'RSA-OAEP',\n modulusLength: 4096,\n publicExponent: new Uint8Array([1, 0, 1]),\n hash: 'SHA-256'\n },\n extractable,\n usages\n )\n\n/**\n * @param {any} jwk\n * @param {Object} opts\n * @param {boolean} [opts.extractable]\n * @param {Usages} [opts.usages]\n */\nexport const importKey = (jwk, { extractable = false, usages } = {}) => {\n if (usages == null) {\n /* c8 ignore next */\n usages = jwk.key_ops || defaultUsages\n }\n return webcrypto.subtle.importKey('jwk', jwk, { name: 'RSA-OAEP', hash: 'SHA-256' }, extractable, /** @type {Usages} */ (usages))\n}\n"],"names":["webcrypto"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,aAAa,GAAG,CAAC,SAAS,EAAE,SAAS,EAAC;AAC5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,OAAO,GAAG,CAAC,GAAG,EAAE,IAAI;AACjC,EAAEA,oBAAS,CAAC,MAAM,CAAC,OAAO;AAC1B,IAAI;AACJ,MAAM,IAA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,EAAE,SAAS,EAAE,EAAE,WAAW,yBAAyB,MAAM,EAAE;AACnI;;;;;;;;"}
1
+ {"version":3,"file":"rsa-oaep.cjs","sources":["../crypto/rsa-oaep.js"],"sourcesContent":["/**\n * RSA-OAEP is an asymmetric keypair used for encryption\n */\n\nimport * as webcrypto from 'lib0/webcrypto'\nexport { exportKeyJwk } from './common.js'\n\n/**\n * @typedef {Array<'encrypt'|'decrypt'>} Usages\n */\n\n/**\n * @type {Usages}\n */\nconst defaultUsages = ['encrypt', 'decrypt']\n\n/**\n * Note that the max data size is limited by the size of the RSA key.\n *\n * @param {CryptoKey} key\n * @param {Uint8Array} data\n * @return {PromiseLike<Uint8Array>}\n */\nexport const encrypt = (key, data) =>\n webcrypto.subtle.encrypt(\n {\n name: 'RSA-OAEP'\n },\n key,\n data\n ).then(buf => new Uint8Array(buf))\n\n/**\n * @experimental The API is not final!\n *\n * Decrypt some data using AES-GCM method.\n *\n * @param {CryptoKey} key\n * @param {Uint8Array} data\n * @return {PromiseLike<Uint8Array>} decrypted buffer\n */\nexport const decrypt = (key, data) =>\n webcrypto.subtle.decrypt(\n {\n name: 'RSA-OAEP'\n },\n key,\n data\n ).then(data => new Uint8Array(data))\n\n/**\n * @param {Object} opts\n * @param {boolean} [opts.extractable]\n * @param {Usages} [opts.usages]\n * @return {Promise<CryptoKeyPair>}\n */\nexport const generateKeyPair = ({ extractable = false, usages = defaultUsages } = {}) =>\n webcrypto.subtle.generateKey(\n {\n name: 'RSA-OAEP',\n modulusLength: 4096,\n publicExponent: new Uint8Array([1, 0, 1]),\n hash: 'SHA-256'\n },\n extractable,\n usages\n )\n\n/**\n * @param {any} jwk\n * @param {Object} opts\n * @param {boolean} [opts.extractable]\n * @param {Usages} [opts.usages]\n */\nexport const importKeyJwk = (jwk, { extractable = false, usages } = {}) => {\n if (usages == null) {\n /* c8 ignore next */\n usages = jwk.key_ops || defaultUsages\n }\n return webcrypto.subtle.importKey('jwk', jwk, { name: 'RSA-OAEP', hash: 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;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,YAAY,GAAG,CAAC,GAAG,EAAE,EAAE,WAAW,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK;AAC3E,EAAE,IAAI,MAAM,IAAI,IAAI,EAAE;AACtB;AACA,IAAI,MAAM,GAAG,GAAG,CAAC,OAAO,IAAI,cAAa;AACzC,GAAG;AACH,EAAE,OAAOA,oBAAS,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,WAAW,yBAAyB,MAAM,EAAE;AACnI;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lib0",
3
- "version": "0.2.80",
3
+ "version": "0.2.81",
4
4
  "description": "",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -469,7 +469,7 @@
469
469
  "clean": "rm -rf dist *.d.ts */*.d.ts *.d.ts.map */*.d.ts.map",
470
470
  "types": "tsc --outDir .",
471
471
  "dist": "rollup -c",
472
- "debug": "npm run gentesthtml && npx 0serve -o test.html",
472
+ "debug": "npm run gentesthtml && node ./bin/0serve.js -o test.html",
473
473
  "test": "c8 --check-coverage --lines 100 --branches 100 --functions 100 --statements 100 node --unhandled-rejections=strict ./test.js --repetition-time 50 --production",
474
474
  "test-inspect": "node --inspect-brk --unhandled-rejections=strict ./test.js --repetition-time 50 --production",
475
475
  "test-extensive": "c8 --check-coverage --lines 100 --branches 100 --functions 100 --statements 100 node test.js --repetition-time 30000 --extensive --production",