@basis-theory/basis-theory-js 1.19.0 → 1.20.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/BasisTheory.d.ts CHANGED
@@ -1,14 +1,12 @@
1
1
  import type { AtomicBanks as ElementsAtomicBanks, AtomicCards as ElementsAtomicCards, BasisTheoryElements, CardElement, CustomizableElementOptions, ElementType, TextElement, TokenizeData as ElementsTokenizeData, Tokens as ElementsTokens } from '@basis-theory/basis-theory-elements-interfaces/elements';
2
2
  import type { TokenizeData } from '@basis-theory/basis-theory-elements-interfaces/models';
3
3
  import type { Applications, AtomicBanks, AtomicCards, BasisTheory as IBasisTheory, BasisTheoryInit, Logs, Permissions, ReactorFormulas, Reactors, RequestOptions, Tenants, Tokens } from '@basis-theory/basis-theory-elements-interfaces/sdk';
4
- import { BasisTheoryEncryptionAdapters } from './encryption/BasisTheoryEncryptionAdapters';
5
4
  import type { BasisTheoryInitOptions, BasisTheoryInitOptionsWithElements, BasisTheoryInitOptionsWithoutElements } from './types';
6
5
  export declare class BasisTheory implements BasisTheoryInit, IBasisTheory, BasisTheoryElements {
7
6
  private _initStatus;
8
7
  private _initOptions?;
9
8
  private _tokens?;
10
9
  private _tokenize?;
11
- private _encryption?;
12
10
  private _elements?;
13
11
  private _applications?;
14
12
  private _tenants?;
@@ -25,10 +23,6 @@ export declare class BasisTheory implements BasisTheoryInit, IBasisTheory, Basis
25
23
  private loadElements;
26
24
  get initOptions(): Required<BasisTheoryInitOptions>;
27
25
  get tokens(): Tokens & ElementsTokens;
28
- /**
29
- * @deprecated
30
- */
31
- get encryption(): BasisTheoryEncryptionAdapters;
32
26
  get applications(): Applications;
33
27
  get tenants(): Tenants;
34
28
  get logs(): Logs;
package/BasisTheory.js CHANGED
@@ -15,8 +15,6 @@ var _elements = require("./elements");
15
15
 
16
16
  var _constants2 = require("./elements/constants");
17
17
 
18
- var _BasisTheoryEncryptionAdapters = require("./encryption/BasisTheoryEncryptionAdapters");
19
-
20
18
  var _logs = require("./logs");
21
19
 
22
20
  var _permissions = require("./permissions");
@@ -110,7 +108,6 @@ class BasisTheory {
110
108
  apiKey,
111
109
  baseURL: new URL(_constants.CLIENT_BASE_PATHS.permissions, baseUrl).toString()
112
110
  });
113
- this._encryption = new _BasisTheoryEncryptionAdapters.BasisTheoryEncryptionAdapters();
114
111
  this._initStatus = 'done';
115
112
  } catch (error) {
116
113
  this._initStatus = 'error';
@@ -159,14 +156,6 @@ class BasisTheory {
159
156
  get tokens() {
160
157
  return (0, _common.assertInit)(this._tokens);
161
158
  }
162
- /**
163
- * @deprecated
164
- */
165
-
166
-
167
- get encryption() {
168
- return (0, _common.assertInit)(this._encryption);
169
- }
170
159
 
171
160
  get applications() {
172
161
  return (0, _common.assertInit)(this._applications);
package/index.d.ts CHANGED
@@ -5,6 +5,5 @@ import type { BasisTheoryInit } from '@basis-theory/basis-theory-elements-interf
5
5
  */
6
6
  export declare const _instance: BasisTheoryInit;
7
7
  export * from './BasisTheory';
8
- export * from './encryption';
9
8
  export * from './applications';
10
9
  export * from './tokens';
package/index.js CHANGED
@@ -22,20 +22,6 @@ Object.keys(_BasisTheory).forEach(function (key) {
22
22
  });
23
23
  });
24
24
 
25
- var _encryption = require("./encryption");
26
-
27
- Object.keys(_encryption).forEach(function (key) {
28
- if (key === "default" || key === "__esModule") return;
29
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
30
- if (key in exports && exports[key] === _encryption[key]) return;
31
- Object.defineProperty(exports, key, {
32
- enumerable: true,
33
- get: function () {
34
- return _encryption[key];
35
- }
36
- });
37
- });
38
-
39
25
  var _applications = require("./applications");
40
26
 
41
27
  Object.keys(_applications).forEach(function (key) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basis-theory/basis-theory-js",
3
- "version": "1.19.0",
3
+ "version": "1.20.0",
4
4
  "repository": "https://github.com/Basis-Theory/basis-theory-js",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
package/types.d.ts CHANGED
@@ -7,14 +7,6 @@ declare type ClientsBasePathMap = {
7
7
  declare type Providers = 'BROWSER' | 'NODE';
8
8
  declare const algorithm: readonly ["RSA", "AES"];
9
9
  declare type Algorithm = typeof algorithm[number];
10
- interface EncryptionProviderOptions {
11
- defaultKeySize: number;
12
- keyExpirationInDays: number;
13
- }
14
- interface EncryptionOptions {
15
- algorithm: Algorithm;
16
- options?: EncryptionProviderOptions;
17
- }
18
10
  interface BasisTheoryInitOptions {
19
11
  apiBaseUrl?: string;
20
12
  }
@@ -31,4 +23,4 @@ declare global {
31
23
  }
32
24
  }
33
25
  export { algorithm };
34
- export type { InitStatus, Clients, ClientsBasePathMap, Providers, Algorithm, EncryptionProviderOptions, EncryptionOptions, BasisTheoryInitOptions, BasisTheoryInitOptionsWithoutElements, BasisTheoryInitOptionsWithElements, };
26
+ export type { InitStatus, Clients, ClientsBasePathMap, Providers, Algorithm, BasisTheoryInitOptions, BasisTheoryInitOptionsWithoutElements, BasisTheoryInitOptionsWithElements, };
@@ -1,12 +0,0 @@
1
- import type { Providers } from '../types';
2
- import { EncryptionOptions } from '../types';
3
- import type { EncryptionAdapter, KeyPair } from './types';
4
- export declare class BasisTheoryEncryption implements EncryptionAdapter {
5
- private readonly adapter;
6
- constructor(encryptionProvider: Providers);
7
- init(encryptionOptions: EncryptionOptions): void;
8
- get name(): string;
9
- generateKeys(): Promise<KeyPair | string | unknown>;
10
- encrypt(encryptionKey: string, plainTextData: string): Promise<string>;
11
- decrypt(decryptionKey: string, cipherTextData: string): Promise<string>;
12
- }
@@ -1,51 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.BasisTheoryEncryption = void 0;
7
-
8
- var _browser = require("./providers/browser");
9
-
10
- var _node = require("./providers/node");
11
-
12
- class BasisTheoryEncryption {
13
- constructor(encryptionProvider) {
14
- switch (encryptionProvider) {
15
- case 'BROWSER':
16
- this.adapter = _browser.browserAdapter;
17
- break;
18
-
19
- case 'NODE':
20
- this.adapter = _node.nodeAdapter;
21
- break;
22
-
23
- default:
24
- throw new Error(`No adapter found for provider name "${encryptionProvider}"`);
25
- }
26
- }
27
-
28
- init(encryptionOptions) {
29
- return this.adapter.init(encryptionOptions);
30
- } // eslint-disable-next-line accessor-pairs
31
-
32
-
33
- get name() {
34
- return this.adapter.name;
35
- }
36
-
37
- generateKeys() {
38
- return this.adapter.generateKeys();
39
- }
40
-
41
- encrypt(encryptionKey, plainTextData) {
42
- return this.adapter.encrypt(encryptionKey, plainTextData);
43
- }
44
-
45
- decrypt(decryptionKey, cipherTextData) {
46
- return this.adapter.decrypt(decryptionKey, cipherTextData);
47
- }
48
-
49
- }
50
-
51
- exports.BasisTheoryEncryption = BasisTheoryEncryption;
@@ -1,8 +0,0 @@
1
- import { BasisTheoryEncryption } from './BasisTheoryEncryption';
2
- export declare class BasisTheoryEncryptionAdapters {
3
- private _nodeEncryption?;
4
- private _browserEncryption?;
5
- constructor();
6
- get browserEncryption(): BasisTheoryEncryption;
7
- get nodeEncryption(): BasisTheoryEncryption;
8
- }
@@ -1,33 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.BasisTheoryEncryptionAdapters = void 0;
7
-
8
- var _common = require("../common");
9
-
10
- var _BasisTheoryEncryption = require("./BasisTheoryEncryption");
11
-
12
- class BasisTheoryEncryptionAdapters {
13
- constructor() {
14
- if (typeof window === 'undefined') {
15
- this._nodeEncryption = new _BasisTheoryEncryption.BasisTheoryEncryption('NODE');
16
- } else {
17
- this._browserEncryption = new _BasisTheoryEncryption.BasisTheoryEncryption('BROWSER');
18
- }
19
- } // eslint-disable-next-line accessor-pairs
20
-
21
-
22
- get browserEncryption() {
23
- return (0, _common.assertInit)(this._browserEncryption);
24
- } // eslint-disable-next-line accessor-pairs
25
-
26
-
27
- get nodeEncryption() {
28
- return (0, _common.assertInit)(this._nodeEncryption);
29
- }
30
-
31
- }
32
-
33
- exports.BasisTheoryEncryptionAdapters = BasisTheoryEncryptionAdapters;
@@ -1,2 +0,0 @@
1
- export * from './BasisTheoryEncryption';
2
- export * from './types';
@@ -1,31 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _BasisTheoryEncryption = require("./BasisTheoryEncryption");
8
-
9
- Object.keys(_BasisTheoryEncryption).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- if (key in exports && exports[key] === _BasisTheoryEncryption[key]) return;
12
- Object.defineProperty(exports, key, {
13
- enumerable: true,
14
- get: function () {
15
- return _BasisTheoryEncryption[key];
16
- }
17
- });
18
- });
19
-
20
- var _types = require("./types");
21
-
22
- Object.keys(_types).forEach(function (key) {
23
- if (key === "default" || key === "__esModule") return;
24
- if (key in exports && exports[key] === _types[key]) return;
25
- Object.defineProperty(exports, key, {
26
- enumerable: true,
27
- get: function () {
28
- return _types[key];
29
- }
30
- });
31
- });
@@ -1,2 +0,0 @@
1
- import type { EncryptionAdapter } from '../types';
2
- export declare const browserAdapter: EncryptionAdapter;
@@ -1,98 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.browserAdapter = void 0;
7
-
8
- var _utils = require("./utils");
9
-
10
- let signAlgorithm;
11
- let algorithm;
12
-
13
- const init = browserEncryption => {
14
- var _browserEncryption$op, _browserEncryption$op2, _browserEncryption$al;
15
-
16
- signAlgorithm = {
17
- name: 'RSA-OAEP',
18
- modulusLength: (_browserEncryption$op = browserEncryption === null || browserEncryption === void 0 ? void 0 : (_browserEncryption$op2 = browserEncryption.options) === null || _browserEncryption$op2 === void 0 ? void 0 : _browserEncryption$op2.defaultKeySize) !== null && _browserEncryption$op !== void 0 ? _browserEncryption$op : 4096,
19
- publicExponent: new Uint8Array([1, 0, 1]),
20
- hash: 'SHA-256'
21
- };
22
- algorithm = (_browserEncryption$al = browserEncryption === null || browserEncryption === void 0 ? void 0 : browserEncryption.algorithm) !== null && _browserEncryption$al !== void 0 ? _browserEncryption$al : 'RSA';
23
- };
24
-
25
- const convertBinaryToPem = (binaryData, label) => {
26
- const base64Cert = (0, _utils.arrayBufferToBase64String)(binaryData);
27
- let pemCert = `-----BEGIN ${label} KEY-----\r\n`;
28
- let nextIndex = 0;
29
-
30
- while (nextIndex < base64Cert.length) {
31
- pemCert += nextIndex + 64 <= base64Cert.length ? `${base64Cert.slice(nextIndex, nextIndex + 64)}\r\n` : `${base64Cert.slice(nextIndex)}\r\n`;
32
- nextIndex += 64;
33
- }
34
-
35
- pemCert += `-----END ${label} KEY-----\r\n`;
36
- return pemCert;
37
- };
38
-
39
- const convertPemToBinary = (pem, label) => {
40
- const lines = pem.split('\n');
41
- let encoded = '';
42
-
43
- for (const line of lines) {
44
- if (line.trim().length > 0 && !line.includes(`-BEGIN ${label} KEY-`) && !line.includes(`-END ${label} KEY-`)) {
45
- encoded = encoded + line.trim();
46
- }
47
- }
48
-
49
- return (0, _utils.base64StringToArrayBuffer)(encoded);
50
- };
51
-
52
- const generateRSAKeys = async () => {
53
- const keyPair = await window.crypto.subtle.generateKey(signAlgorithm, true, ['encrypt', 'decrypt']);
54
- const exportedPublic = await window.crypto.subtle.exportKey('spki', keyPair.publicKey);
55
- const exportedPrivate = await window.crypto.subtle.exportKey('pkcs8', keyPair.privateKey);
56
- return {
57
- publicKey: convertBinaryToPem(exportedPublic, 'PUBLIC'),
58
- privateKey: convertBinaryToPem(exportedPrivate, 'PRIVATE')
59
- };
60
- };
61
-
62
- const generateKeyMap = {
63
- RSA: generateRSAKeys,
64
- AES: () => Promise.reject()
65
- };
66
-
67
- const generateKeys = () => generateKeyMap[algorithm]();
68
-
69
- const loadPublicKey = pem => window.crypto.subtle.importKey('spki', convertPemToBinary(pem, 'PUBLIC'), signAlgorithm, true, ['encrypt']);
70
-
71
- const loadPrivateKey = pem => window.crypto.subtle.importKey('pkcs8', convertPemToBinary(pem, 'PRIVATE'), signAlgorithm, true, ['decrypt']);
72
-
73
- const encrypt = async (publicKey, data) => {
74
- const key = await loadPublicKey(publicKey);
75
- const encrypted = await window.crypto.subtle.encrypt({
76
- name: signAlgorithm.name
77
- }, key, // eslint-disable-next-line node/no-unsupported-features/node-builtins
78
- new TextEncoder().encode(data).buffer);
79
- return (0, _utils.arrayBufferToBase64String)(encrypted);
80
- };
81
-
82
- const decrypt = async (privateKey, data) => {
83
- const key = await loadPrivateKey(privateKey);
84
- const decrypted = await window.crypto.subtle.decrypt({
85
- name: signAlgorithm.name
86
- }, key, (0, _utils.base64StringToArrayBuffer)(data)); // eslint-disable-next-line node/no-unsupported-features/node-builtins
87
-
88
- return new TextDecoder().decode(decrypted);
89
- };
90
-
91
- const browserAdapter = {
92
- name: 'browser',
93
- generateKeys,
94
- init,
95
- encrypt,
96
- decrypt
97
- };
98
- exports.browserAdapter = browserAdapter;
@@ -1,2 +0,0 @@
1
- import { EncryptionAdapter } from '../types';
2
- export declare const nodeAdapter: EncryptionAdapter;
@@ -1,73 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.nodeAdapter = void 0;
7
-
8
- var _crypto = require("crypto");
9
-
10
- let keySize;
11
- let algorithm;
12
-
13
- const init = nodeEncryption => {
14
- var _nodeEncryption$optio, _nodeEncryption$optio2, _nodeEncryption$algor;
15
-
16
- keySize = (_nodeEncryption$optio = nodeEncryption === null || nodeEncryption === void 0 ? void 0 : (_nodeEncryption$optio2 = nodeEncryption.options) === null || _nodeEncryption$optio2 === void 0 ? void 0 : _nodeEncryption$optio2.defaultKeySize) !== null && _nodeEncryption$optio !== void 0 ? _nodeEncryption$optio : 4096;
17
- algorithm = (_nodeEncryption$algor = nodeEncryption === null || nodeEncryption === void 0 ? void 0 : nodeEncryption.algorithm) !== null && _nodeEncryption$algor !== void 0 ? _nodeEncryption$algor : 'RSA';
18
- };
19
-
20
- const generateRSAKeys = () => {
21
- const {
22
- publicKey,
23
- privateKey
24
- } = (0, _crypto.generateKeyPairSync)('rsa', {
25
- modulusLength: keySize,
26
- publicKeyEncoding: {
27
- type: 'spki',
28
- format: 'pem'
29
- },
30
- privateKeyEncoding: {
31
- type: 'pkcs8',
32
- format: 'pem'
33
- }
34
- });
35
- return Promise.resolve({
36
- publicKey,
37
- privateKey
38
- });
39
- };
40
-
41
- const generateKeyMap = {
42
- RSA: generateRSAKeys,
43
- AES: () => Promise.reject()
44
- };
45
-
46
- const generateKeys = () => generateKeyMap[algorithm]();
47
-
48
- const encrypt = (publicKey, data) => {
49
- const encrypted = (0, _crypto.publicEncrypt)({
50
- key: publicKey,
51
- padding: _crypto.constants.RSA_PKCS1_OAEP_PADDING,
52
- oaepHash: 'sha256'
53
- }, Buffer.from(data));
54
- return Promise.resolve(encrypted.toString('base64'));
55
- };
56
-
57
- const decrypt = (privateKey, data) => {
58
- const decrypted = (0, _crypto.privateDecrypt)({
59
- key: privateKey,
60
- padding: _crypto.constants.RSA_PKCS1_OAEP_PADDING,
61
- oaepHash: 'sha256'
62
- }, Buffer.from(data, 'base64'));
63
- return Promise.resolve(decrypted.toString());
64
- };
65
-
66
- const nodeAdapter = {
67
- name: 'node',
68
- generateKeys,
69
- init,
70
- encrypt,
71
- decrypt
72
- };
73
- exports.nodeAdapter = nodeAdapter;
@@ -1,3 +0,0 @@
1
- declare const arrayBufferToBase64String: (arrayBuffer: ArrayBuffer) => string;
2
- declare const base64StringToArrayBuffer: (b64str: string) => ArrayBuffer;
3
- export { arrayBufferToBase64String, base64StringToArrayBuffer };
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.base64StringToArrayBuffer = exports.arrayBufferToBase64String = void 0;
7
-
8
- const arrayBufferToBase64String = arrayBuffer => window.btoa(String.fromCharCode(...new Uint8Array(arrayBuffer)));
9
-
10
- exports.arrayBufferToBase64String = arrayBufferToBase64String;
11
-
12
- const base64StringToArrayBuffer = b64str => {
13
- const binary = window.atob(b64str);
14
- const len = binary.length;
15
- const bytes = new Uint8Array(len);
16
-
17
- for (let i = 0; i < len; i++) {
18
- bytes[i] = binary.charCodeAt(i);
19
- }
20
-
21
- return bytes.buffer;
22
- };
23
-
24
- exports.base64StringToArrayBuffer = base64StringToArrayBuffer;
@@ -1,13 +0,0 @@
1
- import { EncryptionOptions } from '../types';
2
- interface KeyPair {
3
- publicKey: string;
4
- privateKey: string;
5
- }
6
- interface EncryptionAdapter {
7
- name: string;
8
- generateKeys(): Promise<KeyPair | string | unknown>;
9
- init(encryptionOptions: EncryptionOptions): void;
10
- encrypt(encryptionKey: unknown, plainTextData: string): Promise<string>;
11
- decrypt(decryptionKey: unknown, cipherTextData: string): Promise<string>;
12
- }
13
- export { KeyPair, EncryptionAdapter };
@@ -1 +0,0 @@
1
- "use strict";