@opentdf/sdk 0.2.0-beta.1758 → 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/README.md +45 -38
- package/dist/cjs/src/access.js +47 -11
- package/dist/cjs/src/auth/auth.js +5 -5
- package/dist/cjs/src/auth/oidc-clientcredentials-provider.js +1 -1
- package/dist/cjs/src/auth/oidc-externaljwt-provider.js +1 -1
- package/dist/cjs/src/auth/oidc-refreshtoken-provider.js +1 -1
- package/dist/cjs/src/auth/oidc.js +1 -1
- package/dist/cjs/src/auth/providers.js +1 -1
- package/dist/cjs/src/concurrency.js +3 -4
- package/dist/cjs/src/encodings/base64.js +4 -4
- package/dist/cjs/src/encodings/hex.js +5 -6
- package/dist/cjs/src/encodings/index.js +18 -8
- package/dist/cjs/src/errors.js +1 -1
- package/dist/cjs/src/index.js +28 -318
- package/dist/cjs/src/nanoclients.js +285 -0
- package/dist/cjs/src/nanoindex.js +47 -0
- package/dist/cjs/src/nanotdf/Client.js +18 -8
- package/dist/cjs/src/nanotdf/NanoTDF.js +1 -1
- package/dist/cjs/src/nanotdf/decrypt.js +2 -2
- package/dist/cjs/src/nanotdf/encrypt-dataset.js +2 -2
- package/dist/cjs/src/nanotdf/encrypt.js +2 -2
- package/dist/cjs/src/nanotdf/helpers/calculateByCurve.js +3 -4
- package/dist/cjs/src/nanotdf/helpers/getHkdfSalt.js +2 -2
- package/dist/cjs/src/nanotdf/models/Ciphers.js +3 -3
- package/dist/cjs/src/nanotdf/models/EcCurves.js +3 -3
- package/dist/cjs/src/nanotdf/models/Header.js +1 -1
- package/dist/cjs/src/nanotdf/models/Payload.js +1 -1
- package/dist/cjs/src/nanotdf/models/Policy/AbstractPolicy.js +1 -1
- package/dist/cjs/src/nanotdf/models/Policy/EmbeddedPolicy.js +1 -1
- package/dist/cjs/src/nanotdf/models/Policy/PolicyFactory.js +1 -1
- package/dist/cjs/src/nanotdf/models/ResourceLocator.js +1 -1
- package/dist/cjs/src/nanotdf/models/Signature.js +1 -1
- package/dist/cjs/src/nanotdf-crypto/ciphers.js +1 -1
- package/dist/cjs/src/nanotdf-crypto/decrypt.js +2 -2
- package/dist/cjs/src/nanotdf-crypto/digest.js +2 -2
- package/dist/cjs/src/nanotdf-crypto/ecdsaSignature.js +4 -5
- package/dist/cjs/src/nanotdf-crypto/encrypt.js +2 -2
- package/dist/cjs/src/nanotdf-crypto/exportCryptoKey.js +2 -2
- package/dist/cjs/src/nanotdf-crypto/generateKeyPair.js +2 -2
- package/dist/cjs/src/nanotdf-crypto/generateRandomNumber.js +2 -2
- package/dist/cjs/src/nanotdf-crypto/index.js +21 -13
- package/dist/cjs/src/nanotdf-crypto/keyAgreement.js +10 -8
- package/dist/cjs/src/nanotdf-crypto/pemPublicToCrypto.js +20 -11
- package/dist/cjs/src/opentdf.js +251 -0
- package/dist/cjs/src/policy/api.js +2 -3
- package/dist/cjs/src/policy/granter.js +3 -4
- package/dist/cjs/src/seekable.js +157 -0
- package/dist/cjs/src/tdf/AttributeObject.js +2 -4
- package/dist/cjs/src/tdf/Policy.js +1 -2
- package/dist/cjs/src/utils.js +12 -14
- package/dist/cjs/src/version.js +6 -2
- package/dist/cjs/tdf3/index.js +27 -15
- package/dist/cjs/tdf3/src/assertions.js +25 -11
- package/dist/cjs/tdf3/src/binary.js +1 -1
- package/dist/cjs/tdf3/src/ciphers/aes-gcm-cipher.js +1 -1
- package/dist/cjs/tdf3/src/ciphers/symmetric-cipher-base.js +1 -1
- package/dist/cjs/tdf3/src/client/DecoratedReadableStream.js +7 -74
- package/dist/cjs/tdf3/src/client/builders.js +26 -22
- package/dist/cjs/tdf3/src/client/index.js +88 -61
- package/dist/cjs/tdf3/src/client/validation.js +3 -3
- package/dist/cjs/tdf3/src/crypto/crypto-utils.js +1 -1
- package/dist/cjs/tdf3/src/crypto/index.js +18 -18
- package/dist/cjs/tdf3/src/index.js +22 -11
- package/dist/cjs/tdf3/src/models/attribute-set.js +1 -1
- package/dist/cjs/tdf3/src/models/encryption-information.js +3 -3
- package/dist/cjs/tdf3/src/models/key-access.js +67 -35
- package/dist/cjs/tdf3/src/models/policy.js +3 -3
- package/dist/cjs/tdf3/src/tdf.js +177 -151
- package/dist/cjs/tdf3/src/utils/buffer-crc32.js +2 -3
- package/dist/cjs/tdf3/src/utils/index.js +30 -28
- package/dist/cjs/tdf3/src/utils/keysplit.js +4 -5
- package/dist/cjs/tdf3/src/utils/unwrap.js +21 -0
- package/dist/cjs/tdf3/src/utils/zip-reader.js +4 -4
- package/dist/cjs/tdf3/src/utils/zip-writer.js +4 -4
- package/dist/types/src/access.d.ts +3 -0
- package/dist/types/src/access.d.ts.map +1 -1
- package/dist/types/src/auth/providers.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +5 -136
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/nanoclients.d.ts +107 -0
- package/dist/types/src/nanoclients.d.ts.map +1 -0
- package/dist/types/src/nanoindex.d.ts +5 -0
- package/dist/types/src/nanoindex.d.ts.map +1 -0
- package/dist/types/src/nanotdf/enum/CipherEnum.d.ts +1 -1
- package/dist/types/src/nanotdf/enum/CipherEnum.d.ts.map +1 -1
- package/dist/types/src/nanotdf/enum/PolicyTypeEnum.d.ts +1 -1
- package/dist/types/src/nanotdf/enum/PolicyTypeEnum.d.ts.map +1 -1
- package/dist/types/src/nanotdf/models/DefaultParams.d.ts +1 -1
- package/dist/types/src/nanotdf/models/ResourceLocator.d.ts.map +1 -1
- package/dist/types/src/nanotdf-crypto/generateKeyPair.d.ts +1 -1
- package/dist/types/src/nanotdf-crypto/generateKeyPair.d.ts.map +1 -1
- package/dist/types/src/nanotdf-crypto/generateRandomNumber.d.ts +1 -1
- package/dist/types/src/nanotdf-crypto/generateRandomNumber.d.ts.map +1 -1
- package/dist/types/src/nanotdf-crypto/index.d.ts +2 -3
- package/dist/types/src/nanotdf-crypto/index.d.ts.map +1 -1
- package/dist/types/src/nanotdf-crypto/keyAgreement.d.ts.map +1 -1
- package/dist/types/src/opentdf.d.ts +110 -0
- package/dist/types/src/opentdf.d.ts.map +1 -0
- package/dist/types/src/seekable.d.ts +39 -0
- package/dist/types/src/seekable.d.ts.map +1 -0
- package/dist/types/src/tdf/AttributeObject.d.ts +0 -2
- package/dist/types/src/tdf/AttributeObject.d.ts.map +1 -1
- package/dist/types/src/tdf/NanoTDF/NanoTDF.d.ts +2 -2
- package/dist/types/src/tdf/NanoTDF/NanoTDF.d.ts.map +1 -1
- package/dist/types/src/tdf/Policy.d.ts.map +1 -1
- package/dist/types/src/tdf/PolicyObject.d.ts +0 -1
- package/dist/types/src/tdf/PolicyObject.d.ts.map +1 -1
- package/dist/types/src/utils.d.ts +0 -1
- package/dist/types/src/utils.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +4 -0
- package/dist/types/src/version.d.ts.map +1 -1
- package/dist/types/tdf3/index.d.ts +3 -2
- package/dist/types/tdf3/index.d.ts.map +1 -1
- package/dist/types/tdf3/src/assertions.d.ts +3 -3
- package/dist/types/tdf3/src/assertions.d.ts.map +1 -1
- package/dist/types/tdf3/src/client/DecoratedReadableStream.d.ts +1 -13
- package/dist/types/tdf3/src/client/DecoratedReadableStream.d.ts.map +1 -1
- package/dist/types/tdf3/src/client/builders.d.ts +43 -37
- package/dist/types/tdf3/src/client/builders.d.ts.map +1 -1
- package/dist/types/tdf3/src/client/index.d.ts +8 -9
- package/dist/types/tdf3/src/client/index.d.ts.map +1 -1
- package/dist/types/tdf3/src/client/validation.d.ts +3 -3
- package/dist/types/tdf3/src/client/validation.d.ts.map +1 -1
- package/dist/types/tdf3/src/crypto/crypto-utils.d.ts.map +1 -1
- package/dist/types/tdf3/src/index.d.ts +1 -1
- package/dist/types/tdf3/src/index.d.ts.map +1 -1
- package/dist/types/tdf3/src/models/key-access.d.ts +63 -15
- package/dist/types/tdf3/src/models/key-access.d.ts.map +1 -1
- package/dist/types/tdf3/src/models/manifest.d.ts +2 -0
- package/dist/types/tdf3/src/models/manifest.d.ts.map +1 -1
- package/dist/types/tdf3/src/models/policy.d.ts +0 -1
- package/dist/types/tdf3/src/models/policy.d.ts.map +1 -1
- package/dist/types/tdf3/src/tdf.d.ts +20 -24
- package/dist/types/tdf3/src/tdf.d.ts.map +1 -1
- package/dist/types/tdf3/src/utils/index.d.ts +0 -2
- package/dist/types/tdf3/src/utils/index.d.ts.map +1 -1
- package/dist/types/tdf3/src/utils/unwrap.d.ts +2 -0
- package/dist/types/tdf3/src/utils/unwrap.d.ts.map +1 -0
- package/dist/types/tdf3/src/utils/zip-reader.d.ts +1 -1
- package/dist/types/tdf3/src/utils/zip-reader.d.ts.map +1 -1
- package/dist/types/tdf3/src/utils/zip-writer.d.ts +2 -2
- package/dist/web/src/access.js +40 -7
- package/dist/web/src/auth/auth.js +1 -1
- package/dist/web/src/auth/oidc-clientcredentials-provider.js +1 -1
- package/dist/web/src/auth/oidc-externaljwt-provider.js +1 -1
- package/dist/web/src/auth/oidc-refreshtoken-provider.js +1 -1
- package/dist/web/src/auth/oidc.js +1 -1
- package/dist/web/src/auth/providers.js +1 -1
- package/dist/web/src/concurrency.js +1 -1
- package/dist/web/src/encodings/base64.js +1 -1
- package/dist/web/src/encodings/hex.js +1 -1
- package/dist/web/src/errors.js +1 -1
- package/dist/web/src/index.js +6 -310
- package/dist/web/src/nanoclients.js +280 -0
- package/dist/web/src/nanoindex.js +5 -0
- package/dist/web/src/nanotdf/Client.js +1 -1
- package/dist/web/src/nanotdf/NanoTDF.js +1 -1
- package/dist/web/src/nanotdf/encrypt-dataset.js +1 -1
- package/dist/web/src/nanotdf/encrypt.js +1 -1
- package/dist/web/src/nanotdf/models/Ciphers.js +1 -1
- package/dist/web/src/nanotdf/models/EcCurves.js +1 -1
- package/dist/web/src/nanotdf/models/Header.js +1 -1
- package/dist/web/src/nanotdf/models/Payload.js +1 -1
- package/dist/web/src/nanotdf/models/Policy/AbstractPolicy.js +1 -1
- package/dist/web/src/nanotdf/models/Policy/EmbeddedPolicy.js +1 -1
- package/dist/web/src/nanotdf/models/Policy/PolicyFactory.js +1 -1
- package/dist/web/src/nanotdf/models/ResourceLocator.js +1 -1
- package/dist/web/src/nanotdf/models/Signature.js +1 -1
- package/dist/web/src/nanotdf-crypto/ciphers.js +1 -1
- package/dist/web/src/nanotdf-crypto/ecdsaSignature.js +1 -1
- package/dist/web/src/nanotdf-crypto/generateKeyPair.js +2 -2
- package/dist/web/src/nanotdf-crypto/generateRandomNumber.js +2 -2
- package/dist/web/src/nanotdf-crypto/index.js +3 -4
- package/dist/web/src/nanotdf-crypto/keyAgreement.js +9 -6
- package/dist/web/src/nanotdf-crypto/pemPublicToCrypto.js +1 -1
- package/dist/web/src/opentdf.js +242 -0
- package/dist/web/src/policy/api.js +1 -1
- package/dist/web/src/policy/granter.js +1 -1
- package/dist/web/src/seekable.js +148 -0
- package/dist/web/src/tdf/AttributeObject.js +1 -2
- package/dist/web/src/tdf/Policy.js +1 -2
- package/dist/web/src/utils.js +2 -3
- package/dist/web/src/version.js +5 -1
- package/dist/web/tdf3/index.js +3 -2
- package/dist/web/tdf3/src/assertions.js +21 -6
- package/dist/web/tdf3/src/binary.js +1 -1
- package/dist/web/tdf3/src/ciphers/aes-gcm-cipher.js +1 -1
- package/dist/web/tdf3/src/ciphers/symmetric-cipher-base.js +1 -1
- package/dist/web/tdf3/src/client/DecoratedReadableStream.js +4 -68
- package/dist/web/tdf3/src/client/builders.js +26 -22
- package/dist/web/tdf3/src/client/index.js +69 -52
- package/dist/web/tdf3/src/client/validation.js +1 -1
- package/dist/web/tdf3/src/crypto/crypto-utils.js +1 -1
- package/dist/web/tdf3/src/crypto/index.js +1 -1
- package/dist/web/tdf3/src/index.js +2 -2
- package/dist/web/tdf3/src/models/attribute-set.js +1 -1
- package/dist/web/tdf3/src/models/encryption-information.js +3 -3
- package/dist/web/tdf3/src/models/key-access.js +47 -24
- package/dist/web/tdf3/src/models/policy.js +1 -1
- package/dist/web/tdf3/src/tdf.js +149 -130
- package/dist/web/tdf3/src/utils/buffer-crc32.js +1 -1
- package/dist/web/tdf3/src/utils/index.js +1 -5
- package/dist/web/tdf3/src/utils/keysplit.js +1 -1
- package/dist/web/tdf3/src/utils/unwrap.js +18 -0
- package/dist/web/tdf3/src/utils/zip-reader.js +1 -1
- package/dist/web/tdf3/src/utils/zip-writer.js +1 -1
- package/package.json +45 -42
- package/src/access.ts +37 -1
- package/src/index.ts +5 -435
- package/src/nanoclients.ts +405 -0
- package/src/nanoindex.ts +4 -0
- package/src/nanotdf-crypto/generateKeyPair.ts +1 -1
- package/src/nanotdf-crypto/generateRandomNumber.ts +1 -1
- package/src/nanotdf-crypto/index.ts +2 -3
- package/src/nanotdf-crypto/keyAgreement.ts +14 -7
- package/src/opentdf.ts +473 -0
- package/{tdf3/src/utils/chunkers.ts → src/seekable.ts} +69 -20
- package/src/tdf/AttributeObject.ts +0 -3
- package/src/tdf/Policy.ts +0 -1
- package/src/tdf/PolicyObject.ts +0 -1
- package/src/utils.ts +1 -3
- package/src/version.ts +5 -0
- package/tdf3/index.ts +14 -2
- package/tdf3/src/assertions.ts +33 -8
- package/tdf3/src/client/DecoratedReadableStream.ts +2 -78
- package/tdf3/src/client/builders.ts +44 -26
- package/tdf3/src/client/index.ts +101 -86
- package/tdf3/src/index.ts +1 -1
- package/tdf3/src/models/encryption-information.ts +2 -2
- package/tdf3/src/models/key-access.ts +120 -38
- package/tdf3/src/models/manifest.ts +3 -0
- package/tdf3/src/models/policy.ts +0 -1
- package/tdf3/src/tdf.ts +251 -207
- package/tdf3/src/utils/index.ts +0 -5
- package/tdf3/src/utils/unwrap.ts +17 -0
- package/tdf3/src/utils/zip-reader.ts +1 -1
- package/dist/cjs/src/nanotdf-crypto/importRawKey.js +0 -18
- package/dist/cjs/tdf3/src/templates/default.html.js +0 -98
- package/dist/cjs/tdf3/src/templates/escaper.js +0 -15
- package/dist/cjs/tdf3/src/templates/index.js +0 -12
- package/dist/cjs/tdf3/src/utils/chunkers.js +0 -114
- package/dist/cjs/tdf3/src/version.js +0 -6
- package/dist/types/src/nanotdf-crypto/importRawKey.d.ts +0 -13
- package/dist/types/src/nanotdf-crypto/importRawKey.d.ts.map +0 -1
- package/dist/types/tdf3/src/templates/default.html.d.ts +0 -8
- package/dist/types/tdf3/src/templates/default.html.d.ts.map +0 -1
- package/dist/types/tdf3/src/templates/escaper.d.ts +0 -6
- package/dist/types/tdf3/src/templates/escaper.d.ts.map +0 -1
- package/dist/types/tdf3/src/templates/index.d.ts +0 -3
- package/dist/types/tdf3/src/templates/index.d.ts.map +0 -1
- package/dist/types/tdf3/src/utils/chunkers.d.ts +0 -29
- package/dist/types/tdf3/src/utils/chunkers.d.ts.map +0 -1
- package/dist/types/tdf3/src/version.d.ts +0 -3
- package/dist/types/tdf3/src/version.d.ts.map +0 -1
- package/dist/web/src/nanotdf-crypto/importRawKey.js +0 -15
- package/dist/web/tdf3/src/templates/default.html.js +0 -96
- package/dist/web/tdf3/src/templates/escaper.js +0 -10
- package/dist/web/tdf3/src/templates/index.js +0 -3
- package/dist/web/tdf3/src/utils/chunkers.js +0 -107
- package/dist/web/tdf3/src/version.js +0 -3
- package/src/nanotdf-crypto/importRawKey.ts +0 -19
- package/tdf3/src/templates/default.html.ts +0 -105
- package/tdf3/src/templates/escaper.ts +0 -10
- package/tdf3/src/templates/index.ts +0 -2
- package/tdf3/src/version.ts +0 -2
package/dist/cjs/src/index.js
CHANGED
|
@@ -15,328 +15,38 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
24
37
|
};
|
|
25
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.clientType = exports.version = exports.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const access_js_1 = require("./access.js");
|
|
32
|
-
const errors_js_1 = require("./errors.js");
|
|
39
|
+
exports.tdfSpecVersion = exports.clientType = exports.version = exports.attributeFQNsAsValues = exports.AuthProviders = exports.withHeaders = exports.HttpRequest = void 0;
|
|
40
|
+
var auth_js_1 = require("./auth/auth.js");
|
|
41
|
+
Object.defineProperty(exports, "HttpRequest", { enumerable: true, get: function () { return auth_js_1.HttpRequest; } });
|
|
42
|
+
Object.defineProperty(exports, "withHeaders", { enumerable: true, get: function () { return auth_js_1.withHeaders; } });
|
|
43
|
+
exports.AuthProviders = __importStar(require("./auth/providers.js"));
|
|
33
44
|
var api_js_1 = require("./policy/api.js");
|
|
34
45
|
Object.defineProperty(exports, "attributeFQNsAsValues", { enumerable: true, get: function () { return api_js_1.attributeFQNsAsValues; } });
|
|
35
|
-
// Define default options
|
|
36
|
-
const defaultOptions = {
|
|
37
|
-
ecdsaBinding: false,
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* NanoTDF SDK Client
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```
|
|
44
|
-
* import { clientSecretAuthProvider, NanoTDFClient } from '@opentdf/sdk';
|
|
45
|
-
*
|
|
46
|
-
* const OIDC_ENDPOINT = 'http://localhost:65432/auth/realms/opentdf-demo';
|
|
47
|
-
* const KAS_URL = 'http://localhost:65432/api/kas/';
|
|
48
|
-
*
|
|
49
|
-
* const ciphertext = '...';
|
|
50
|
-
* const client = new NanoTDFClient({
|
|
51
|
-
* authProvider: await clientSecretAuthProvider({
|
|
52
|
-
* clientId: 'tdf-client',
|
|
53
|
-
* clientSecret: '123-456',
|
|
54
|
-
* oidcOrigin: OIDC_ENDPOINT,
|
|
55
|
-
* }),
|
|
56
|
-
* kasEndpoint: KAS_URL
|
|
57
|
-
* }
|
|
58
|
-
* );
|
|
59
|
-
* client.decrypt(ciphertext)
|
|
60
|
-
* .then(plaintext => {
|
|
61
|
-
* console.log('Plaintext', plaintext);
|
|
62
|
-
* })
|
|
63
|
-
* .catch(err => {
|
|
64
|
-
* console.error('Some error occurred', err);
|
|
65
|
-
* })
|
|
66
|
-
*/
|
|
67
|
-
class NanoTDFClient extends index_js_1.Client {
|
|
68
|
-
/**
|
|
69
|
-
* Decrypt ciphertext
|
|
70
|
-
*
|
|
71
|
-
* Pass a base64 string, TypedArray, or ArrayBuffer ciphertext and get a promise which resolves plaintext
|
|
72
|
-
*
|
|
73
|
-
* @param ciphertext Ciphertext to decrypt
|
|
74
|
-
*/
|
|
75
|
-
async decrypt(ciphertext) {
|
|
76
|
-
// Parse ciphertext
|
|
77
|
-
const nanotdf = index_js_1.NanoTDF.from(ciphertext);
|
|
78
|
-
// TODO: The version number should be fetched from the API
|
|
79
|
-
const version = '0.0.1';
|
|
80
|
-
const kasUrl = nanotdf.header.getKasRewrapUrl();
|
|
81
|
-
// Rewrap key on every request
|
|
82
|
-
const ukey = await this.rewrapKey(nanotdf.header.toBuffer(), kasUrl, nanotdf.header.magicNumberVersion, version);
|
|
83
|
-
if (!ukey) {
|
|
84
|
-
throw new Error('internal: key rewrap failure');
|
|
85
|
-
}
|
|
86
|
-
// Return decrypt promise
|
|
87
|
-
return (0, index_js_1.decrypt)(ukey, nanotdf);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Decrypt ciphertext of the legacy TDF, with the older, smaller i.v. calculation.
|
|
91
|
-
*
|
|
92
|
-
* Pass a base64 string, TypedArray, or ArrayBuffer ciphertext and get a promise which resolves plaintext
|
|
93
|
-
*
|
|
94
|
-
* @param ciphertext Ciphertext to decrypt
|
|
95
|
-
*/
|
|
96
|
-
async decryptLegacyTDF(ciphertext) {
|
|
97
|
-
// Parse ciphertext
|
|
98
|
-
const nanotdf = index_js_1.NanoTDF.from(ciphertext, undefined, true);
|
|
99
|
-
const legacyVersion = '0.0.0';
|
|
100
|
-
// Rewrap key on every request
|
|
101
|
-
const key = await this.rewrapKey(nanotdf.header.toBuffer(), nanotdf.header.getKasRewrapUrl(), nanotdf.header.magicNumberVersion, legacyVersion);
|
|
102
|
-
if (!key) {
|
|
103
|
-
throw new Error('internal: failed unwrap');
|
|
104
|
-
}
|
|
105
|
-
// Return decrypt promise
|
|
106
|
-
return (0, index_js_1.decrypt)(key, nanotdf);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Encrypts the given data using the NanoTDF encryption scheme.
|
|
110
|
-
*
|
|
111
|
-
* @param {string | TypedArray | ArrayBuffer} data - The data to be encrypted.
|
|
112
|
-
* @param {EncryptOptions} [options=defaultOptions] - The encryption options (currently unused).
|
|
113
|
-
* @returns {Promise<ArrayBuffer>} A promise that resolves to the encrypted data as an ArrayBuffer.
|
|
114
|
-
* @throws {Error} If the initialization vector is not a number.
|
|
115
|
-
*/
|
|
116
|
-
async encrypt(data, options) {
|
|
117
|
-
// For encrypt always generate the client ephemeralKeyPair
|
|
118
|
-
const ephemeralKeyPair = await this.ephemeralKeyPair;
|
|
119
|
-
const initializationVector = this.iv;
|
|
120
|
-
if (typeof initializationVector !== 'number') {
|
|
121
|
-
throw new errors_js_1.ConfigurationError('NanoTDF clients are single use. Please generate a new client and keypair.');
|
|
122
|
-
}
|
|
123
|
-
delete this.iv;
|
|
124
|
-
if (!this.kasPubKey) {
|
|
125
|
-
this.kasPubKey = await (0, access_js_1.fetchECKasPubKey)(this.kasUrl);
|
|
126
|
-
}
|
|
127
|
-
// Create a policy for the tdf
|
|
128
|
-
const policy = new Policy_js_1.Policy();
|
|
129
|
-
// Add data attributes.
|
|
130
|
-
for (const dataAttribute of this.dataAttributes) {
|
|
131
|
-
const attribute = await (0, AttributeObject_js_1.createAttribute)(dataAttribute, this.kasPubKey, this.kasUrl);
|
|
132
|
-
policy.addAttribute(attribute);
|
|
133
|
-
}
|
|
134
|
-
if (this.dissems.length == 0 && this.dataAttributes.length == 0) {
|
|
135
|
-
console.warn('This policy has an empty attributes list and an empty dissemination list. This will allow any entity with a valid Entity Object to access this TDF.');
|
|
136
|
-
}
|
|
137
|
-
// Encrypt the policy.
|
|
138
|
-
const policyObjectAsStr = policy.toJSON();
|
|
139
|
-
// IV is always '1', since the new keypair is generated on encrypt
|
|
140
|
-
// using the same key is fine.
|
|
141
|
-
const lengthAsUint32 = new Uint32Array(1);
|
|
142
|
-
lengthAsUint32[0] = initializationVector;
|
|
143
|
-
const lengthAsUint24 = new Uint8Array(lengthAsUint32.buffer);
|
|
144
|
-
// NOTE: We are only interested in only first 3 bytes.
|
|
145
|
-
const payloadIV = new Uint8Array(12).fill(0);
|
|
146
|
-
payloadIV[9] = lengthAsUint24[2];
|
|
147
|
-
payloadIV[10] = lengthAsUint24[1];
|
|
148
|
-
payloadIV[11] = lengthAsUint24[0];
|
|
149
|
-
const mergedOptions = { ...defaultOptions, ...options };
|
|
150
|
-
return (0, index_js_1.encrypt)(policyObjectAsStr, this.kasPubKey, ephemeralKeyPair, payloadIV, data, mergedOptions.ecdsaBinding);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
exports.NanoTDFClient = NanoTDFClient;
|
|
154
|
-
/**
|
|
155
|
-
* NanoTDF Dataset SDK Client
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
* @example
|
|
159
|
-
* ```
|
|
160
|
-
* import { clientSecretAuthProvider, NanoTDFDatasetClient } from '@opentdf/sdk';
|
|
161
|
-
*
|
|
162
|
-
* const OIDC_ENDPOINT = 'http://localhost:65432/auth/realms/tdf';
|
|
163
|
-
* const KAS_URL = 'http://localhost:65432/api/kas/';
|
|
164
|
-
*
|
|
165
|
-
* const ciphertext = '...';
|
|
166
|
-
* const client = new NanoTDFDatasetClient({
|
|
167
|
-
* authProvider: await clientSecretAuthProvider({
|
|
168
|
-
* clientId: 'tdf-client',
|
|
169
|
-
* clientSecret: '123-456',
|
|
170
|
-
* exchange: 'client',
|
|
171
|
-
* oidcOrigin: OIDC_ENDPOINT,
|
|
172
|
-
* }),
|
|
173
|
-
* kasEndpoint: KAS_URL,
|
|
174
|
-
* });
|
|
175
|
-
* const plaintext = client.decrypt(ciphertext);
|
|
176
|
-
* console.log('Plaintext', plaintext);
|
|
177
|
-
* ```
|
|
178
|
-
*/
|
|
179
|
-
class NanoTDFDatasetClient extends index_js_1.Client {
|
|
180
|
-
/**
|
|
181
|
-
* Create new NanoTDF Dataset Client
|
|
182
|
-
*
|
|
183
|
-
* The Ephemeral Key Pair can either be provided or will be generate when fetching the entity object. Once set it
|
|
184
|
-
* cannot be changed. If a new ephemeral key is desired it a new client should be initialized.
|
|
185
|
-
* There is no performance impact for creating a new client IFF the ephemeral key pair is provided.
|
|
186
|
-
*
|
|
187
|
-
* @param clientConfig OIDC client credentials
|
|
188
|
-
* @param kasUrl Key access service URL
|
|
189
|
-
* @param ephemeralKeyPair (optional) ephemeral key pair to use
|
|
190
|
-
* @param maxKeyIterations Max iteration to performe without a key rotation
|
|
191
|
-
*/
|
|
192
|
-
constructor(opts) {
|
|
193
|
-
if (opts.maxKeyIterations &&
|
|
194
|
-
opts.maxKeyIterations > NanoTDFDatasetClient.NTDF_MAX_KEY_ITERATIONS) {
|
|
195
|
-
throw new errors_js_1.ConfigurationError(`key iteration exceeds max iterations(${NanoTDFDatasetClient.NTDF_MAX_KEY_ITERATIONS})`);
|
|
196
|
-
}
|
|
197
|
-
super(opts);
|
|
198
|
-
this.maxKeyIteration = opts.maxKeyIterations || NanoTDFDatasetClient.NTDF_MAX_KEY_ITERATIONS;
|
|
199
|
-
this.keyIterationCount = 0;
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Encrypt data
|
|
203
|
-
*
|
|
204
|
-
* Pass a string, TypedArray, or ArrayBuffer data and get a promise which resolves ciphertext
|
|
205
|
-
*
|
|
206
|
-
* @param data to decrypt
|
|
207
|
-
*/
|
|
208
|
-
async encrypt(data, options) {
|
|
209
|
-
// Intial encrypt
|
|
210
|
-
if (this.keyIterationCount == 0) {
|
|
211
|
-
const mergedOptions = { ...defaultOptions, ...options };
|
|
212
|
-
this.ecdsaBinding = mergedOptions.ecdsaBinding;
|
|
213
|
-
// For encrypt always generate the client ephemeralKeyPair
|
|
214
|
-
const ephemeralKeyPair = await this.ephemeralKeyPair;
|
|
215
|
-
if (!this.kasPubKey) {
|
|
216
|
-
this.kasPubKey = await (0, access_js_1.fetchECKasPubKey)(this.kasUrl);
|
|
217
|
-
}
|
|
218
|
-
// Create a policy for the tdf
|
|
219
|
-
const policy = new Policy_js_1.Policy();
|
|
220
|
-
// Add data attributes.
|
|
221
|
-
for (const dataAttribute of this.dataAttributes) {
|
|
222
|
-
const attribute = await (0, AttributeObject_js_1.createAttribute)(dataAttribute, this.kasPubKey, this.kasUrl);
|
|
223
|
-
policy.addAttribute(attribute);
|
|
224
|
-
}
|
|
225
|
-
if (this.dissems.length == 0 || this.dataAttributes.length == 0) {
|
|
226
|
-
console.warn('This policy has an empty attributes list and an empty dissemination list. This will allow any entity with a valid Entity Object to access this TDF.');
|
|
227
|
-
}
|
|
228
|
-
// Encrypt the policy.
|
|
229
|
-
const policyObjectAsStr = policy.toJSON();
|
|
230
|
-
const ivVector = this.generateIV();
|
|
231
|
-
// Generate a symmetric key.
|
|
232
|
-
this.symmetricKey = await (0, index_js_2.keyAgreement)(ephemeralKeyPair.privateKey, await this.kasPubKey.key, await (0, index_js_1.getHkdfSalt)(index_js_1.DefaultParams.magicNumberVersion));
|
|
233
|
-
const nanoTDFBuffer = await (0, index_js_1.encrypt)(policyObjectAsStr, this.kasPubKey, ephemeralKeyPair, ivVector, data, this.ecdsaBinding);
|
|
234
|
-
// Cache the header and increment the key iteration
|
|
235
|
-
if (!this.cachedHeader) {
|
|
236
|
-
const nanoTDF = index_js_1.NanoTDF.from(nanoTDFBuffer);
|
|
237
|
-
this.cachedHeader = nanoTDF.header;
|
|
238
|
-
}
|
|
239
|
-
this.keyIterationCount += 1;
|
|
240
|
-
return nanoTDFBuffer;
|
|
241
|
-
}
|
|
242
|
-
this.keyIterationCount += 1;
|
|
243
|
-
if (!this.cachedHeader) {
|
|
244
|
-
throw new errors_js_1.ConfigurationError('invalid dataset client: empty nanoTDF header');
|
|
245
|
-
}
|
|
246
|
-
if (!this.symmetricKey) {
|
|
247
|
-
throw new errors_js_1.ConfigurationError('invalid dataset client: empty dek');
|
|
248
|
-
}
|
|
249
|
-
this.keyIterationCount += 1;
|
|
250
|
-
if (this.keyIterationCount == this.maxKeyIteration) {
|
|
251
|
-
// reset the key iteration
|
|
252
|
-
this.keyIterationCount = 0;
|
|
253
|
-
}
|
|
254
|
-
const ivVector = this.generateIV();
|
|
255
|
-
return (0, index_js_1.encryptDataset)(this.symmetricKey, this.cachedHeader, ivVector, data);
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Decrypt ciphertext
|
|
259
|
-
*
|
|
260
|
-
* Pass a base64 string, TypedArray, or ArrayBuffer ciphertext and get a promise which resolves plaintext
|
|
261
|
-
*
|
|
262
|
-
* @param ciphertext Ciphertext to decrypt
|
|
263
|
-
*/
|
|
264
|
-
async decrypt(ciphertext) {
|
|
265
|
-
// Parse ciphertext
|
|
266
|
-
const nanotdf = index_js_1.NanoTDF.from(ciphertext);
|
|
267
|
-
if (!this.cachedEphemeralKey) {
|
|
268
|
-
// First decrypt
|
|
269
|
-
return this.rewrapAndDecrypt(nanotdf);
|
|
270
|
-
}
|
|
271
|
-
// Other encrypts
|
|
272
|
-
if (this.cachedEphemeralKey.toString() == nanotdf.header.ephemeralPublicKey.toString()) {
|
|
273
|
-
const ukey = this.unwrappedKey;
|
|
274
|
-
if (!ukey) {
|
|
275
|
-
// These should have thrown already.
|
|
276
|
-
throw new Error('internal: key rewrap failure');
|
|
277
|
-
}
|
|
278
|
-
// Return decrypt promise
|
|
279
|
-
return (0, index_js_1.decrypt)(ukey, nanotdf);
|
|
280
|
-
}
|
|
281
|
-
else {
|
|
282
|
-
return this.rewrapAndDecrypt(nanotdf);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
async rewrapAndDecrypt(nanotdf) {
|
|
286
|
-
// TODO: The version number should be fetched from the API
|
|
287
|
-
const version = '0.0.1';
|
|
288
|
-
// Rewrap key on every request
|
|
289
|
-
const ukey = await this.rewrapKey(nanotdf.header.toBuffer(), nanotdf.header.getKasRewrapUrl(), nanotdf.header.magicNumberVersion, version);
|
|
290
|
-
if (!ukey) {
|
|
291
|
-
// These should have thrown already.
|
|
292
|
-
throw new Error('internal: key rewrap failure');
|
|
293
|
-
}
|
|
294
|
-
this.cachedEphemeralKey = nanotdf.header.ephemeralPublicKey;
|
|
295
|
-
this.unwrappedKey = ukey;
|
|
296
|
-
// Return decrypt promise
|
|
297
|
-
return (0, index_js_1.decrypt)(ukey, nanotdf);
|
|
298
|
-
}
|
|
299
|
-
generateIV() {
|
|
300
|
-
const iv = this.iv;
|
|
301
|
-
if (iv === undefined) {
|
|
302
|
-
// iv has passed the maximum iteration count for this dek
|
|
303
|
-
throw new errors_js_1.ConfigurationError('dataset full');
|
|
304
|
-
}
|
|
305
|
-
// assert iv ∈ ℤ ∩ (0, 2^24)
|
|
306
|
-
if (!Number.isInteger(iv) || iv <= 0 || 16777215 < iv) {
|
|
307
|
-
// Something has fiddled with the iv outside of the expected behavior
|
|
308
|
-
// could indicate a race condition, e.g. if two workers or handlers are
|
|
309
|
-
// processing the file at once, for example.
|
|
310
|
-
throw new Error('internal: invalid state');
|
|
311
|
-
}
|
|
312
|
-
const lengthAsUint32 = new Uint32Array(1);
|
|
313
|
-
lengthAsUint32[0] = iv;
|
|
314
|
-
const lengthAsUint24 = new Uint8Array(lengthAsUint32.buffer);
|
|
315
|
-
// NOTE: We are only interested in only first 3 bytes.
|
|
316
|
-
const ivVector = new Uint8Array(index_js_1.Client.IV_SIZE).fill(0);
|
|
317
|
-
ivVector[9] = lengthAsUint24[2];
|
|
318
|
-
ivVector[10] = lengthAsUint24[1];
|
|
319
|
-
ivVector[11] = lengthAsUint24[0];
|
|
320
|
-
// Increment the IV
|
|
321
|
-
if (iv == 16777215) {
|
|
322
|
-
delete this.iv;
|
|
323
|
-
}
|
|
324
|
-
else {
|
|
325
|
-
this.iv = iv + 1;
|
|
326
|
-
}
|
|
327
|
-
return ivVector;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
exports.NanoTDFDatasetClient = NanoTDFDatasetClient;
|
|
331
|
-
// Total unique IVs(2^24 -1) used for encrypting the nano tdf payloads
|
|
332
|
-
// IV starts from 1 since the 0 IV is reserved for policy encryption
|
|
333
|
-
NanoTDFDatasetClient.NTDF_MAX_KEY_ITERATIONS = 8388606;
|
|
334
|
-
/**
|
|
335
|
-
* Authorization for connecting authZ tokens to
|
|
336
|
-
* remote requests.
|
|
337
|
-
*/
|
|
338
|
-
exports.AuthProviders = __importStar(require("./auth/providers.js"));
|
|
339
46
|
var version_js_1 = require("./version.js");
|
|
340
47
|
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return version_js_1.version; } });
|
|
341
48
|
Object.defineProperty(exports, "clientType", { enumerable: true, get: function () { return version_js_1.clientType; } });
|
|
342
|
-
|
|
49
|
+
Object.defineProperty(exports, "tdfSpecVersion", { enumerable: true, get: function () { return version_js_1.tdfSpecVersion; } });
|
|
50
|
+
__exportStar(require("./opentdf.js"), exports);
|
|
51
|
+
__exportStar(require("./seekable.js"), exports);
|
|
52
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBQUEsMENBQThGO0FBQWpELHNHQUFBLFdBQVcsT0FBQTtBQUFFLHNHQUFBLFdBQVcsT0FBQTtBQUNyRSxxRUFBcUQ7QUFDckQsMENBQXdEO0FBQS9DLCtHQUFBLHFCQUFxQixPQUFBO0FBQzlCLDJDQUFtRTtBQUExRCxxR0FBQSxPQUFPLE9BQUE7QUFBRSx3R0FBQSxVQUFVLE9BQUE7QUFBRSw0R0FBQSxjQUFjLE9BQUE7QUFDNUMsK0NBQTZCO0FBQzdCLGdEQUE4QiJ9
|