@keetanetwork/keetanet-client 0.16.2 → 0.18.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/client/index-browser.js +509 -159
- package/client/index.js +511 -137
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/KeetaNetSDK.Client.html +4 -4
- package/docs/classes/KeetaNetSDK.Referenced.BaseSet.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BaseVoteBuilder.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.Block.html +3 -3
- package/docs/classes/KeetaNetSDK.Referenced.BlockBuilder.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockHash.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperation.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationCREATE_IDENTIFIER.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationMANAGE_CERTIFICATE.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationMODIFY_PERMISSIONS.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationRECEIVE.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationSEND.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationSET_INFO.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationSET_REP.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationTOKEN_ADMIN_MODIFY_BALANCE.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.BlockOperationTOKEN_ADMIN_SUPPLY.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.CertificateHash.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSAKeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256K1KeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256K1PrivateKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256K1PublicKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256K1Signature.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256R1KeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256R1PrivateKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256R1PublicKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ECDSASECP256R1Signature.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ED25519KeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ED25519PrivateKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ED25519PublicKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ED25519Signature.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ExternalKeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.ExternalSet.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.IdempotentKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.IdentifierKey.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.IdentifierKeyPair.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.KeetaNetError.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.KeetaNetErrorBase.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.KeetaNetLedgerError.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.KeetaNetLedgerIdempotentKeyError.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.KeetaNetLedgerVoteError.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.KeyInterface.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.KeyStorage.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.Ledger.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.LedgerAtomicInterface.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.PermissionSetHolder.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.PossiblyExpiredVote.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.PossiblyUnsignedBlock.html +3 -3
- package/docs/classes/KeetaNetSDK.Referenced.SignatureStorage.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.Stats.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.StatsPending.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.UnsignedBlock.html +3 -3
- package/docs/classes/KeetaNetSDK.Referenced.Vote.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteBlockBundle.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.VoteBlockHash.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteBuilder.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteHash.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteLikeBase.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteQuote.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteQuoteBuilder.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.VoteStaple.html +2 -2
- package/docs/classes/KeetaNetSDK.Referenced.VoteStapleHash.html +1 -1
- package/docs/classes/KeetaNetSDK.Referenced.src_lib_utils_buffer.BufferStorage.html +1 -1
- package/docs/classes/KeetaNetSDK.UserClient.html +4 -4
- package/docs/hierarchy.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ASN1ExplicitContextTag.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ASN1ImplicitContextTag.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ASN1Object.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.AccountACLRow.html +11 -0
- package/docs/interfaces/KeetaNetSDK.Referenced.AccountComputedEffect.html +4 -0
- package/docs/interfaces/KeetaNetSDK.Referenced.BaseACLRow.html +9 -0
- package/docs/interfaces/KeetaNetSDK.Referenced.BaseAccountInfo.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BaseExternalKeyPairFunctions.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BaseGenerationConfig.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BaseIdentifierAccountInfo.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BaseIdentifierCreateArguments.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperation.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationCREATE_IDENTIFIER.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationMANAGE_CERTIFICATE.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationMODIFY_PERMISSIONS.html +2 -2
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationRECEIVE.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationSEND.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationSET_INFO.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationSET_REP.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationTOKEN_ADMIN_MODIFY_BALANCE.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockJSONOperationTOKEN_ADMIN_SUPPLY.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockV1Canonical.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.BlockV2Canonical.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.CertificateACLPrincipal.html +4 -0
- package/docs/interfaces/KeetaNetSDK.Referenced.CertificateACLRow.html +11 -0
- package/docs/interfaces/KeetaNetSDK.Referenced.CertificateComputedEffect.html +5 -0
- package/docs/interfaces/KeetaNetSDK.Referenced.ComputedBlocksEffectFields.html +2 -2
- package/docs/interfaces/KeetaNetSDK.Referenced.Constructor.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.DisposableTimingHandle.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ECDSA_SECP256K1AccountInfo.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ECDSA_SECP256R1AccountInfo.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ED25519AccountInfo.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ExternalKeyPairFunctionsNoEncryption.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ExternalKeyPairFunctionsSupportsEncryption.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.InitialConfigSupply.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.InstanceSet.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.KVGenericOptionsType.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.KVSetOptionsType.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.LedgerStorageAPI.html +3 -3
- package/docs/interfaces/KeetaNetSDK.Referenced.ListACLsByEntityFilters.html +4 -0
- package/docs/interfaces/KeetaNetSDK.Referenced.ModifyTokenBalanceEntry.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.MultiSigIdentifierCreateArguments.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.MultisigAccountInfo.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.MultisigConfig.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.NetworkAccountInfo.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.NumericValueEntry.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.P2PPeerBase.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.P2PPeerListener.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.P2PPeerRepBase.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.PrincipalACLWithInfoParsed.html +2 -7
- package/docs/interfaces/KeetaNetSDK.Referenced.PublicKeyStorage.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.PublishOptions.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.RequestTokenReceiveEntry.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.StorageAccountInfo.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.TokenAccountInfo.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.TokenNumericEntry.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.UserClientConfig.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.UserClientOptions.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.VoteStapleJSON.html +2 -2
- package/docs/interfaces/KeetaNetSDK.Referenced.WithIsInstance.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1BitString.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1Date.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1OID.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1Set.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1String.html +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.src_lib_utils_asn1.ASN1Struct.html +1 -1
- package/docs/modules/KeetaNetSDK.Referenced.html +1 -1
- package/docs/types/KeetaNetSDK.Referenced.ACLEntryUnparsed.html +1 -5
- package/docs/types/KeetaNetSDK.Referenced.ACLPermissionRequirement.html +2 -0
- package/docs/types/KeetaNetSDK.Referenced.ACLPrincipalType.html +1 -0
- package/docs/types/KeetaNetSDK.Referenced.ACLRow.html +2 -0
- package/docs/types/KeetaNetSDK.Referenced.ACLUpdate.html +5 -0
- package/docs/types/KeetaNetSDK.Referenced.ComputedBlockEffect.html +2 -0
- package/docs/types/KeetaNetSDK.Referenced.ComputedEffectOfBlocks.html +2 -2
- package/docs/types/KeetaNetSDK.Referenced.ComputedEffectOfBlocksByEntity.html +2 -0
- package/docs/types/KeetaNetSDK.Referenced.ModifyPermissionsPrincipal.html +1 -0
- package/docs/types/KeetaNetSDK.Referenced.ModifyPermissionsPrincipalInput.html +1 -0
- package/docs/variables/KeetaNetSDK.Referenced.BlockOperationASN1Schema.html +2 -2
- package/docs/variables/KeetaNetSDK.Referenced.FullLedgerBaseErrorCode.html +1 -1
- package/docs/variables/KeetaNetSDK.Referenced.aclPrincipalType.html +1 -0
- package/docs/variables/KeetaNetSDK.Referenced.allFullErrorCodes.html +1 -1
- package/lib/block/index.d.ts +14 -2
- package/lib/block/operations.d.ts +40 -4
- package/lib/error/block.d.ts +2 -2
- package/lib/error/index.d.ts +1 -1
- package/lib/error/ledger.d.ts +3 -3
- package/lib/ledger/common.d.ts +7 -5
- package/lib/ledger/db_dynamodb.d.ts +2 -2
- package/lib/ledger/db_postgres.d.ts +3 -3
- package/lib/ledger/db_spanner.d.ts +3 -3
- package/lib/ledger/db_spanner_helper.d.ts +23 -3
- package/lib/ledger/db_sqlite.d.ts +3 -3
- package/lib/ledger/effects.d.ts +17 -9
- package/lib/ledger/index.d.ts +14 -5
- package/lib/ledger/types.d.ts +38 -14
- package/lib/log/target_gcp.js +19 -17
- package/lib/utils/external-keys/gcp-kms-wrapped.d.ts +85 -0
- package/lib/utils/external-keys/gcp-kms-wrapped.js +453 -0
- package/lib/utils/external-keys/gcp-kms.common.d.ts +17 -0
- package/lib/utils/external-keys/gcp-kms.d.ts +4 -9
- package/lib/utils/external-keys/gcp-kms.js +52 -39
- package/lib/utils/external-keys/passkey-prf.d.ts +42 -1
- package/lib/utils/external-keys/passkey-prf.js +107 -13
- package/lib/vote.d.ts +7 -1
- package/npm-shrinkwrap.json +24 -24
- package/package.json +1 -1
- package/version.d.ts +1 -1
- package/docs/interfaces/KeetaNetSDK.Referenced.ACLEntry.html +0 -10
- package/docs/interfaces/KeetaNetSDK.Referenced.ACLRow.html +0 -10
- package/docs/interfaces/KeetaNetSDK.Referenced.ACLUpdate.html +0 -12
- package/docs/interfaces/KeetaNetSDK.Referenced.ComputedBlockEffect.html +0 -4
- package/docs/types/KeetaNetSDK.Referenced.ComputedEffectOfBlocksByAccount.html +0 -2
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
/******/ (() => { // webpackBootstrap
|
|
2
|
+
/******/ "use strict";
|
|
3
|
+
/******/ // The require scope
|
|
4
|
+
/******/ var __webpack_require__ = {};
|
|
5
|
+
/******/
|
|
6
|
+
/************************************************************************/
|
|
7
|
+
/******/ /* webpack/runtime/define property getters */
|
|
8
|
+
/******/ (() => {
|
|
9
|
+
/******/ // define getter functions for harmony exports
|
|
10
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
11
|
+
/******/ for(var key in definition) {
|
|
12
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
13
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
14
|
+
/******/ }
|
|
15
|
+
/******/ }
|
|
16
|
+
/******/ };
|
|
17
|
+
/******/ })();
|
|
18
|
+
/******/
|
|
19
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
20
|
+
/******/ (() => {
|
|
21
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
22
|
+
/******/ })();
|
|
23
|
+
/******/
|
|
24
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
25
|
+
/******/ (() => {
|
|
26
|
+
/******/ // define __esModule on exports
|
|
27
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
28
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
29
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
30
|
+
/******/ }
|
|
31
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
32
|
+
/******/ };
|
|
33
|
+
/******/ })();
|
|
34
|
+
/******/
|
|
35
|
+
/************************************************************************/
|
|
36
|
+
var __webpack_exports__ = {};
|
|
37
|
+
// ESM COMPAT FLAG
|
|
38
|
+
__webpack_require__.r(__webpack_exports__);
|
|
39
|
+
|
|
40
|
+
// EXPORTS
|
|
41
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
42
|
+
KeetaGCPKMSWrappedKeyPairFactory: () => (/* binding */ KeetaGCPKMSWrappedKeyPairFactory)
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
;// ./src/lib/utils/external-keys/gcp-kms.common.ts
|
|
46
|
+
/**
|
|
47
|
+
* Parse a full KMS key name into its components.
|
|
48
|
+
* Example: projects/<project_name>/locations/<location>/keyRings/<keyRingName>/cryptoKeys/<keyName>
|
|
49
|
+
*/
|
|
50
|
+
function parseGCPKMSKeyName(fullName) {
|
|
51
|
+
const pattern = /^projects\/([^/]+)\/locations\/([^/]+)\/keyRings\/([^/]+)\/cryptoKeys\/([^/]+)(?:\/cryptoKeyVersions\/(\d+))?$/;
|
|
52
|
+
const match = fullName.match(pattern);
|
|
53
|
+
if (!match) {
|
|
54
|
+
throw new Error(`Invalid KMS key name format: ${fullName}`);
|
|
55
|
+
}
|
|
56
|
+
const projectId = match[1];
|
|
57
|
+
const locationId = match[2];
|
|
58
|
+
const keyRingId = match[3];
|
|
59
|
+
const keyId = match[4];
|
|
60
|
+
const versionId = match[5];
|
|
61
|
+
if (!projectId || !locationId || !keyRingId || !keyId) {
|
|
62
|
+
throw new Error(`Invalid KMS key name format: ${fullName}`);
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
projectId,
|
|
66
|
+
locationId,
|
|
67
|
+
keyRingId,
|
|
68
|
+
keyId,
|
|
69
|
+
versionId
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Build a full KMS key resource name from components.
|
|
75
|
+
*/
|
|
76
|
+
async function buildGCPKMSKeyNameBase(gcpKMSClientClass, config) {
|
|
77
|
+
var _cryptoKey$primary$na, _cryptoKey$primary;
|
|
78
|
+
let lookupVersion = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
79
|
+
const base = `projects/${config.projectId}/locations/${config.locationId}/keyRings/${config.keyRingId}/cryptoKeys/${config.keyId}`;
|
|
80
|
+
if (config.versionId) {
|
|
81
|
+
return `${base}/cryptoKeyVersions/${config.versionId}`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/*
|
|
85
|
+
* Just omit the version if it's not requested
|
|
86
|
+
*/
|
|
87
|
+
if (!lookupVersion) {
|
|
88
|
+
return base;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/*
|
|
92
|
+
* If the versionID is missing, get the latest
|
|
93
|
+
* version from KMS.
|
|
94
|
+
*/
|
|
95
|
+
const client = new gcpKMSClientClass({
|
|
96
|
+
projectId: config.projectId
|
|
97
|
+
});
|
|
98
|
+
const [cryptoKey] = await client.getCryptoKey({
|
|
99
|
+
name: base
|
|
100
|
+
});
|
|
101
|
+
const latestVersionNumber = (_cryptoKey$primary$na = (_cryptoKey$primary = cryptoKey.primary) === null || _cryptoKey$primary === void 0 || (_cryptoKey$primary = _cryptoKey$primary.name) === null || _cryptoKey$primary === void 0 ? void 0 : _cryptoKey$primary.split('/').at(-1)) !== null && _cryptoKey$primary$na !== void 0 ? _cryptoKey$primary$na : '1';
|
|
102
|
+
return `${base}/cryptoKeyVersions/${latestVersionNumber}`;
|
|
103
|
+
}
|
|
104
|
+
;// ./src/lib/utils/external-keys/gcp-kms-wrapped.ts
|
|
105
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
106
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
107
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
108
|
+
/**
|
|
109
|
+
* ExternalKeyPair for the Keeta Network which uses Google Cloud KMS
|
|
110
|
+
* to wrap private key operations. This allows users to leverage GCP KMS for
|
|
111
|
+
* decrypting an encrypted private key and performing signing and encryption
|
|
112
|
+
* operations without exposing the private key material to the application.
|
|
113
|
+
*
|
|
114
|
+
* Internally, it uses RSA keys on GCP KMS to support decrypting the
|
|
115
|
+
* supplied encrypted keying material.
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
/** @internal */
|
|
121
|
+
|
|
122
|
+
/** @internal */
|
|
123
|
+
|
|
124
|
+
/** @internal */
|
|
125
|
+
|
|
126
|
+
function KeetaGCPKMSWrappedKeyPairFactory(packages) {
|
|
127
|
+
let includeTesting = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
128
|
+
if (!packages.KeyManagementServiceClient || !packages.KeetaNet) {
|
|
129
|
+
throw new Error('Missing required packages for KeetaGCPKMSWrappedKeyPairFactory');
|
|
130
|
+
}
|
|
131
|
+
const KeetaNet = Object.freeze({
|
|
132
|
+
lib: Object.freeze({
|
|
133
|
+
Account: packages.KeetaNet.lib.Account,
|
|
134
|
+
Utils: Object.freeze({
|
|
135
|
+
Helper: Object.freeze({
|
|
136
|
+
bufferToArrayBuffer: packages.KeetaNet.lib.Utils.Helper.bufferToArrayBuffer
|
|
137
|
+
}),
|
|
138
|
+
Buffer: packages.KeetaNet.lib.Utils.Buffer
|
|
139
|
+
})
|
|
140
|
+
})
|
|
141
|
+
});
|
|
142
|
+
const bufferToArrayBuffer = KeetaNet.lib.Utils.Helper.bufferToArrayBuffer;
|
|
143
|
+
const Buffer = KeetaNet.lib.Utils.Buffer.Buffer;
|
|
144
|
+
const crypto = packages.crypto;
|
|
145
|
+
function keyTypeToAccountKeyAlgorithm(keyType) {
|
|
146
|
+
if (typeof keyType === 'number') {
|
|
147
|
+
if (!(keyType in KeetaNet.lib.Account.AccountKeyAlgorithm)) {
|
|
148
|
+
throw new Error(`Invalid keyType value: ${keyType}`);
|
|
149
|
+
}
|
|
150
|
+
return keyType;
|
|
151
|
+
} else if (typeof keyType === 'string') {
|
|
152
|
+
if (Number(keyType).toString() === keyType) {
|
|
153
|
+
throw new Error(`Invalid keyType value: ${keyType}, expected a string key type name, not a number in string form`);
|
|
154
|
+
}
|
|
155
|
+
if (!(keyType in KeetaNet.lib.Account.AccountKeyAlgorithm)) {
|
|
156
|
+
throw new Error(`Invalid keyType value: ${keyType}`);
|
|
157
|
+
}
|
|
158
|
+
const retval = KeetaNet.lib.Account.AccountKeyAlgorithm[keyType];
|
|
159
|
+
if (typeof retval !== 'number') {
|
|
160
|
+
throw new Error(`Invalid keyType value: ${keyType}, expected a string key type name that maps to a number`);
|
|
161
|
+
}
|
|
162
|
+
return retval;
|
|
163
|
+
} else {
|
|
164
|
+
throw new Error(`Invalid keyType value: ${keyType}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function keyTypeToAccountKeyAlgorithmString(keyType) {
|
|
168
|
+
const keyTypeNumber = keyTypeToAccountKeyAlgorithm(keyType);
|
|
169
|
+
const keyTypeString = KeetaNet.lib.Account.AccountKeyAlgorithm[keyTypeNumber];
|
|
170
|
+
return keyTypeString;
|
|
171
|
+
}
|
|
172
|
+
async function buildGCPKMSKeyName(config) {
|
|
173
|
+
let lookupVersion = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
174
|
+
return await buildGCPKMSKeyNameBase(packages.KeyManagementServiceClient, config, lookupVersion);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* A KeyPair implementation for the Keeta Network which uses the
|
|
179
|
+
* Google Cloud KMS to decrypt private keying material so that
|
|
180
|
+
* signing and encryption operations can be performed without exposing
|
|
181
|
+
* the private key material to the application.
|
|
182
|
+
*/
|
|
183
|
+
class KeetaGCPKMSWrappedKeyPair {
|
|
184
|
+
static createAccountFromSeed(seed, index, keyType) {
|
|
185
|
+
if (KeetaNet.lib.Account.isIdentifierKeyType(keyType)) {
|
|
186
|
+
throw new Error('May only construct accounts from keying material for signing keys, not identifier keys');
|
|
187
|
+
}
|
|
188
|
+
const account = KeetaNet.lib.Account.fromSeed(seed, index !== null && index !== void 0 ? index : 0, keyType);
|
|
189
|
+
return account;
|
|
190
|
+
}
|
|
191
|
+
static async lookupKey(options) {
|
|
192
|
+
let keyConfig;
|
|
193
|
+
if (typeof options.kmsKey === 'string') {
|
|
194
|
+
keyConfig = parseGCPKMSKeyName(options.kmsKey);
|
|
195
|
+
} else {
|
|
196
|
+
keyConfig = options.kmsKey;
|
|
197
|
+
}
|
|
198
|
+
let cleanupClient = true;
|
|
199
|
+
const client = new packages.KeyManagementServiceClient({
|
|
200
|
+
projectId: keyConfig.projectId
|
|
201
|
+
});
|
|
202
|
+
try {
|
|
203
|
+
const keyVersionName = await buildGCPKMSKeyName(keyConfig);
|
|
204
|
+
const [publicKeyResponse] = await client.getPublicKey({
|
|
205
|
+
name: keyVersionName
|
|
206
|
+
});
|
|
207
|
+
const publicKeyPEM = publicKeyResponse.pem;
|
|
208
|
+
if (!publicKeyPEM) {
|
|
209
|
+
throw new Error('No public key PEM returned from KMS');
|
|
210
|
+
}
|
|
211
|
+
let padding;
|
|
212
|
+
if (publicKeyResponse.algorithm === 'RSA_DECRYPT_OAEP_4096_SHA512') {
|
|
213
|
+
padding = {
|
|
214
|
+
type: 'OAEP',
|
|
215
|
+
hash: 'sha512'
|
|
216
|
+
};
|
|
217
|
+
} else if (publicKeyResponse.algorithm === 'RSA_DECRYPT_OAEP_4096_SHA256') {
|
|
218
|
+
padding = {
|
|
219
|
+
type: 'OAEP',
|
|
220
|
+
hash: 'sha256'
|
|
221
|
+
};
|
|
222
|
+
} else {
|
|
223
|
+
throw new Error(`Unsupported KMS key algorithm: ${publicKeyResponse.algorithm}`);
|
|
224
|
+
}
|
|
225
|
+
cleanupClient = false;
|
|
226
|
+
return {
|
|
227
|
+
client,
|
|
228
|
+
keyVersionName,
|
|
229
|
+
publicKeyPEM,
|
|
230
|
+
padding
|
|
231
|
+
};
|
|
232
|
+
} finally {
|
|
233
|
+
if (cleanupClient) {
|
|
234
|
+
await client.close();
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Encrypt a private key material with the KMS key and return
|
|
241
|
+
* the encryptedSeed that can be stored and later
|
|
242
|
+
* decrypted with the same KMS key.
|
|
243
|
+
*/
|
|
244
|
+
static async encryptSeed(input, options) {
|
|
245
|
+
if (crypto === undefined) {
|
|
246
|
+
throw new Error('Crypto module is required for encrypting seed with KMS public key');
|
|
247
|
+
}
|
|
248
|
+
const keyType = keyTypeToAccountKeyAlgorithm(options.keyType);
|
|
249
|
+
|
|
250
|
+
/*
|
|
251
|
+
* Verify we can create an account from this keying material
|
|
252
|
+
*
|
|
253
|
+
* This will throw if the input data is incorrect or invalid
|
|
254
|
+
*/
|
|
255
|
+
this.createAccountFromSeed(input, options.index, keyType);
|
|
256
|
+
|
|
257
|
+
/*
|
|
258
|
+
* Lookup the KMS key
|
|
259
|
+
*/
|
|
260
|
+
const {
|
|
261
|
+
client,
|
|
262
|
+
publicKeyPEM,
|
|
263
|
+
padding
|
|
264
|
+
} = await this.lookupKey(options);
|
|
265
|
+
await client.close();
|
|
266
|
+
const publicKey = crypto.createPublicKey(publicKeyPEM);
|
|
267
|
+
const encryptedSeed = crypto.publicEncrypt({
|
|
268
|
+
key: publicKey,
|
|
269
|
+
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
|
|
270
|
+
oaepHash: padding.hash
|
|
271
|
+
}, Buffer.from(input));
|
|
272
|
+
return bufferToArrayBuffer(encryptedSeed);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Lookup (or open) an existing GCP KMS key and create a
|
|
277
|
+
* Account instance for it.
|
|
278
|
+
*/
|
|
279
|
+
static async lookup(options) {
|
|
280
|
+
const keyType = keyTypeToAccountKeyAlgorithm(options.keyType);
|
|
281
|
+
const {
|
|
282
|
+
client,
|
|
283
|
+
keyVersionName
|
|
284
|
+
} = await this.lookupKey(options);
|
|
285
|
+
let decryptResponse;
|
|
286
|
+
try {
|
|
287
|
+
/* Decrypt the encrypted keying material using the KMS key */
|
|
288
|
+
const decryptResponseWrapper = await client.asymmetricDecrypt({
|
|
289
|
+
name: keyVersionName,
|
|
290
|
+
ciphertext: Buffer.from(options.encryptedSeed)
|
|
291
|
+
});
|
|
292
|
+
decryptResponse = decryptResponseWrapper[0];
|
|
293
|
+
} finally {
|
|
294
|
+
await client.close();
|
|
295
|
+
}
|
|
296
|
+
const seed = decryptResponse.plaintext;
|
|
297
|
+
let seedBuffer;
|
|
298
|
+
if (Buffer.isBuffer(seed)) {
|
|
299
|
+
seedBuffer = seed;
|
|
300
|
+
} else if (seed instanceof Uint8Array) {
|
|
301
|
+
seedBuffer = Buffer.from(seed);
|
|
302
|
+
} else if (typeof seed === 'string') {
|
|
303
|
+
seedBuffer = Buffer.from(seed, 'base64');
|
|
304
|
+
} else {
|
|
305
|
+
throw new Error('Decryption failed, no plaintext returned from KMS');
|
|
306
|
+
}
|
|
307
|
+
const account = this.createAccountFromSeed(bufferToArrayBuffer(seedBuffer), options.index, keyType);
|
|
308
|
+
return account;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Allow looking up an existing KMS key and creating a
|
|
313
|
+
* Account instance from it using a JSON representation
|
|
314
|
+
* of the options.
|
|
315
|
+
*
|
|
316
|
+
* Base64 encoding is used for the encryptedSeed in the
|
|
317
|
+
* JSON representation since ArrayBuffers cannot be directly
|
|
318
|
+
* represented in JSON.
|
|
319
|
+
*/
|
|
320
|
+
|
|
321
|
+
static async lookupFromJSON(input) {
|
|
322
|
+
if (typeof input !== 'object' || input === null) {
|
|
323
|
+
throw new Error('Invalid input, expected an object');
|
|
324
|
+
}
|
|
325
|
+
if (!('kmsKey' in input)) {
|
|
326
|
+
throw new Error('Missing kmsKey in input');
|
|
327
|
+
}
|
|
328
|
+
const kmsKeyInput = input.kmsKey;
|
|
329
|
+
let kmsKey;
|
|
330
|
+
if (typeof kmsKeyInput !== 'string' && (typeof kmsKeyInput !== 'object' || kmsKeyInput === null)) {
|
|
331
|
+
throw new Error('Invalid kmsKey in input, expected a string or object');
|
|
332
|
+
}
|
|
333
|
+
if (typeof kmsKeyInput === 'object') {
|
|
334
|
+
if (!('projectId' in kmsKeyInput) || typeof kmsKeyInput.projectId !== 'string') {
|
|
335
|
+
throw new Error('Invalid or missing projectId in kmsKey');
|
|
336
|
+
}
|
|
337
|
+
if (!('locationId' in kmsKeyInput) || typeof kmsKeyInput.locationId !== 'string') {
|
|
338
|
+
throw new Error('Invalid or missing locationId in kmsKey');
|
|
339
|
+
}
|
|
340
|
+
if (!('keyRingId' in kmsKeyInput) || typeof kmsKeyInput.keyRingId !== 'string') {
|
|
341
|
+
throw new Error('Invalid or missing keyRingId in kmsKey');
|
|
342
|
+
}
|
|
343
|
+
if (!('keyId' in kmsKeyInput) || typeof kmsKeyInput.keyId !== 'string') {
|
|
344
|
+
throw new Error('Invalid or missing keyId in kmsKey');
|
|
345
|
+
}
|
|
346
|
+
let kmsKeyInputVersionIdObject;
|
|
347
|
+
if ('versionId' in kmsKeyInput) {
|
|
348
|
+
if (typeof kmsKeyInput.versionId !== 'string') {
|
|
349
|
+
throw new Error('Invalid versionId in kmsKey, expected a string');
|
|
350
|
+
}
|
|
351
|
+
if (kmsKeyInput.versionId === '') {
|
|
352
|
+
throw new Error('Invalid versionId in kmsKey, cannot be an empty string');
|
|
353
|
+
}
|
|
354
|
+
kmsKeyInputVersionIdObject = {
|
|
355
|
+
versionId: kmsKeyInput.versionId
|
|
356
|
+
};
|
|
357
|
+
} else {
|
|
358
|
+
kmsKeyInputVersionIdObject = {};
|
|
359
|
+
}
|
|
360
|
+
kmsKey = {
|
|
361
|
+
projectId: kmsKeyInput.projectId,
|
|
362
|
+
locationId: kmsKeyInput.locationId,
|
|
363
|
+
keyRingId: kmsKeyInput.keyRingId,
|
|
364
|
+
keyId: kmsKeyInput.keyId,
|
|
365
|
+
...kmsKeyInputVersionIdObject
|
|
366
|
+
};
|
|
367
|
+
} else {
|
|
368
|
+
kmsKey = kmsKeyInput;
|
|
369
|
+
}
|
|
370
|
+
if (!('keyType' in input) || typeof input.keyType !== 'string' && typeof input.keyType !== 'number') {
|
|
371
|
+
throw new Error('Invalid or missing keyType in input');
|
|
372
|
+
}
|
|
373
|
+
if (!('encryptedSeed' in input) || typeof input.encryptedSeed !== 'string') {
|
|
374
|
+
throw new Error('Invalid or missing encryptedSeed in input');
|
|
375
|
+
}
|
|
376
|
+
if (!('type' in input) || input.type !== 'gcpkmswrapped') {
|
|
377
|
+
throw new Error('Invalid or missing type in input, expected "gcpkmswrapped"');
|
|
378
|
+
}
|
|
379
|
+
let index = 0;
|
|
380
|
+
if ('index' in input) {
|
|
381
|
+
if (typeof input.index !== 'number' || !Number.isInteger(input.index) || input.index < 0) {
|
|
382
|
+
throw new Error('Invalid index in input, must be a non-negative integer');
|
|
383
|
+
}
|
|
384
|
+
index = input.index;
|
|
385
|
+
}
|
|
386
|
+
const encryptedSeed = input.encryptedSeed;
|
|
387
|
+
const keyTypeString = input.keyType;
|
|
388
|
+
if (!(keyTypeString in KeetaNet.lib.Account.AccountKeyAlgorithm)) {
|
|
389
|
+
throw new Error(`Invalid keyType value: ${keyTypeString}`);
|
|
390
|
+
}
|
|
391
|
+
let keyType;
|
|
392
|
+
if (Number.isNaN(Number(keyTypeString))) {
|
|
393
|
+
// @ts-ignore
|
|
394
|
+
keyType = KeetaNet.lib.Account.AccountKeyAlgorithm[keyTypeString];
|
|
395
|
+
} else {
|
|
396
|
+
keyType = Number(keyTypeString);
|
|
397
|
+
}
|
|
398
|
+
if (typeof keyType !== 'number') {
|
|
399
|
+
throw new Error(`Invalid keyType value: ${keyTypeString}`);
|
|
400
|
+
}
|
|
401
|
+
const options = {
|
|
402
|
+
kmsKey: kmsKey,
|
|
403
|
+
keyType: keyType,
|
|
404
|
+
encryptedSeed: bufferToArrayBuffer(Buffer.from(encryptedSeed, 'base64')),
|
|
405
|
+
index: index
|
|
406
|
+
};
|
|
407
|
+
return await this.lookup(options);
|
|
408
|
+
}
|
|
409
|
+
static async lookupFromString(input) {
|
|
410
|
+
const parsed = JSON.parse(input);
|
|
411
|
+
return await this.lookupFromJSON(parsed);
|
|
412
|
+
}
|
|
413
|
+
static async getJSONFromOptions(options) {
|
|
414
|
+
var _options$index;
|
|
415
|
+
let kmsKey = options.kmsKey;
|
|
416
|
+
if (typeof kmsKey !== 'string') {
|
|
417
|
+
kmsKey = await buildGCPKMSKeyName(kmsKey);
|
|
418
|
+
}
|
|
419
|
+
const keyTypeString = keyTypeToAccountKeyAlgorithmString(options.keyType);
|
|
420
|
+
const json = {
|
|
421
|
+
type: 'gcpkmswrapped',
|
|
422
|
+
kmsKey: kmsKey,
|
|
423
|
+
keyType: keyTypeString,
|
|
424
|
+
encryptedSeed: Buffer.from(options.encryptedSeed).toString('base64'),
|
|
425
|
+
index: (_options$index = options.index) !== null && _options$index !== void 0 ? _options$index : 0
|
|
426
|
+
};
|
|
427
|
+
return json;
|
|
428
|
+
}
|
|
429
|
+
static async getStringFromOptions(options) {
|
|
430
|
+
const json = await this.getJSONFromOptions(options);
|
|
431
|
+
return JSON.stringify(json);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
/** @internal */
|
|
435
|
+
_defineProperty(KeetaGCPKMSWrappedKeyPair, "_Testing", {});
|
|
436
|
+
if (!includeTesting) {
|
|
437
|
+
/**
|
|
438
|
+
* The _Testing property is only included for testing
|
|
439
|
+
* so remove it if we're not including testing.
|
|
440
|
+
*/
|
|
441
|
+
// @ts-ignore
|
|
442
|
+
delete KeetaGCPKMSWrappedKeyPair._Testing;
|
|
443
|
+
}
|
|
444
|
+
Object.freeze(KeetaGCPKMSWrappedKeyPair);
|
|
445
|
+
Object.freeze(KeetaGCPKMSWrappedKeyPair.prototype);
|
|
446
|
+
return KeetaGCPKMSWrappedKeyPair;
|
|
447
|
+
}
|
|
448
|
+
Object.freeze(KeetaGCPKMSWrappedKeyPairFactory);
|
|
449
|
+
var __webpack_export_target__ = exports;
|
|
450
|
+
for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i];
|
|
451
|
+
if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
|
|
452
|
+
/******/ })()
|
|
453
|
+
;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { KeyManagementServiceClient } from '@google-cloud/kms';
|
|
2
|
+
export interface GCPKMSKeyConfig {
|
|
3
|
+
projectId: string;
|
|
4
|
+
locationId: string;
|
|
5
|
+
keyRingId: string;
|
|
6
|
+
keyId: string;
|
|
7
|
+
versionId?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Parse a full KMS key name into its components.
|
|
11
|
+
* Example: projects/<project_name>/locations/<location>/keyRings/<keyRingName>/cryptoKeys/<keyName>
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseGCPKMSKeyName(fullName: string): GCPKMSKeyConfig;
|
|
14
|
+
/**
|
|
15
|
+
* Build a full KMS key resource name from components.
|
|
16
|
+
*/
|
|
17
|
+
export declare function buildGCPKMSKeyNameBase(gcpKMSClientClass: typeof KeyManagementServiceClient, config: GCPKMSKeyConfig, lookupVersion?: boolean): Promise<string>;
|
|
@@ -8,6 +8,7 @@ import type { KeyManagementServiceClient } from '@google-cloud/kms';
|
|
|
8
8
|
import type * as KeetaNet from '../../../client';
|
|
9
9
|
import type { AccountKeyAlgorithm } from '../../../lib/account';
|
|
10
10
|
import type * as crypto from 'node:crypto';
|
|
11
|
+
import type { GCPKMSKeyConfig } from './gcp-kms.common';
|
|
11
12
|
type KeetaGCPKMSKeyPairPackages = {
|
|
12
13
|
KeyManagementServiceClient: typeof KeyManagementServiceClient;
|
|
13
14
|
KeetaNet: {
|
|
@@ -27,27 +28,21 @@ type KeetaGCPKMSKeyPairOptions = {
|
|
|
27
28
|
* The GCP KMS key resource name or config object.
|
|
28
29
|
* Format: projects/<project>/locations/<location>/keyRings/<keyRing>/cryptoKeys/<key>
|
|
29
30
|
*/
|
|
30
|
-
key: string |
|
|
31
|
-
projectId: string;
|
|
32
|
-
locationId: string;
|
|
33
|
-
keyRingId: string;
|
|
34
|
-
keyId: string;
|
|
35
|
-
versionId?: string;
|
|
36
|
-
};
|
|
31
|
+
key: string | GCPKMSKeyConfig;
|
|
37
32
|
/**
|
|
38
33
|
* Key type for the KMS key. Optional - will be auto-detected from KMS
|
|
39
34
|
* if not provided, but can be explicitly specified for validation.
|
|
40
35
|
*/
|
|
41
36
|
keyType?: AccountKeyAlgorithm;
|
|
42
37
|
};
|
|
43
|
-
interface
|
|
38
|
+
interface KeetaGCPKMSKeyPairInterface extends InstanceType<typeof KeetaNet.lib.Account.ExternalKeyPair> {
|
|
44
39
|
/**
|
|
45
40
|
* The full GCP KMS key resource name used for this key pair.
|
|
46
41
|
*/
|
|
47
42
|
readonly keyName: string;
|
|
48
43
|
}
|
|
49
44
|
interface KeetaGCPKMSKeyPairClass {
|
|
50
|
-
lookup: (options: KeetaGCPKMSKeyPairOptions) => Promise<
|
|
45
|
+
lookup: (options: KeetaGCPKMSKeyPairOptions) => Promise<KeetaGCPKMSKeyPairInterface>;
|
|
51
46
|
}
|
|
52
47
|
export declare function KeetaGCPKMSKeyPairFactory(packages: KeetaGCPKMSKeyPairPackages): Omit<KeetaGCPKMSKeyPairClass, '_Testing'>;
|
|
53
48
|
export {};
|
|
@@ -34,20 +34,15 @@
|
|
|
34
34
|
/******/
|
|
35
35
|
/************************************************************************/
|
|
36
36
|
var __webpack_exports__ = {};
|
|
37
|
+
// ESM COMPAT FLAG
|
|
37
38
|
__webpack_require__.r(__webpack_exports__);
|
|
38
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
39
|
-
/* harmony export */ KeetaGCPKMSKeyPairFactory: () => (/* binding */ KeetaGCPKMSKeyPairFactory)
|
|
40
|
-
/* harmony export */ });
|
|
41
|
-
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
42
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
43
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
44
|
-
/**
|
|
45
|
-
* ExternalKeyPair for the Keeta Network which uses Google Cloud KMS
|
|
46
|
-
* for signing operations. This implementation supports ECDSA keys on
|
|
47
|
-
* both SECP256K1 and SECP256R1 curves, with potential for ED25519
|
|
48
|
-
* support in the future.
|
|
49
|
-
*/
|
|
50
39
|
|
|
40
|
+
// EXPORTS
|
|
41
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
42
|
+
KeetaGCPKMSKeyPairFactory: () => (/* binding */ KeetaGCPKMSKeyPairFactory)
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
;// ./src/lib/utils/external-keys/gcp-kms.common.ts
|
|
51
46
|
/**
|
|
52
47
|
* Parse a full KMS key name into its components.
|
|
53
48
|
* Example: projects/<project_name>/locations/<location>/keyRings/<keyRingName>/cryptoKeys/<keyName>
|
|
@@ -75,6 +70,50 @@ function parseGCPKMSKeyName(fullName) {
|
|
|
75
70
|
};
|
|
76
71
|
}
|
|
77
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Build a full KMS key resource name from components.
|
|
75
|
+
*/
|
|
76
|
+
async function buildGCPKMSKeyNameBase(gcpKMSClientClass, config) {
|
|
77
|
+
var _cryptoKey$primary$na, _cryptoKey$primary;
|
|
78
|
+
let lookupVersion = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
79
|
+
const base = `projects/${config.projectId}/locations/${config.locationId}/keyRings/${config.keyRingId}/cryptoKeys/${config.keyId}`;
|
|
80
|
+
if (config.versionId) {
|
|
81
|
+
return `${base}/cryptoKeyVersions/${config.versionId}`;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/*
|
|
85
|
+
* Just omit the version if it's not requested
|
|
86
|
+
*/
|
|
87
|
+
if (!lookupVersion) {
|
|
88
|
+
return base;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/*
|
|
92
|
+
* If the versionID is missing, get the latest
|
|
93
|
+
* version from KMS.
|
|
94
|
+
*/
|
|
95
|
+
const client = new gcpKMSClientClass({
|
|
96
|
+
projectId: config.projectId
|
|
97
|
+
});
|
|
98
|
+
const [cryptoKey] = await client.getCryptoKey({
|
|
99
|
+
name: base
|
|
100
|
+
});
|
|
101
|
+
const latestVersionNumber = (_cryptoKey$primary$na = (_cryptoKey$primary = cryptoKey.primary) === null || _cryptoKey$primary === void 0 || (_cryptoKey$primary = _cryptoKey$primary.name) === null || _cryptoKey$primary === void 0 ? void 0 : _cryptoKey$primary.split('/').at(-1)) !== null && _cryptoKey$primary$na !== void 0 ? _cryptoKey$primary$na : '1';
|
|
102
|
+
return `${base}/cryptoKeyVersions/${latestVersionNumber}`;
|
|
103
|
+
}
|
|
104
|
+
;// ./src/lib/utils/external-keys/gcp-kms.ts
|
|
105
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
106
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
107
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
108
|
+
/**
|
|
109
|
+
* ExternalKeyPair for the Keeta Network which uses Google Cloud KMS
|
|
110
|
+
* for signing operations. This implementation supports ECDSA keys on
|
|
111
|
+
* both SECP256K1 and SECP256R1 curves, with potential for ED25519
|
|
112
|
+
* support in the future.
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
78
117
|
/** @internal */
|
|
79
118
|
|
|
80
119
|
/** @internal */
|
|
@@ -107,32 +146,8 @@ function KeetaGCPKMSKeyPairFactory(packages) {
|
|
|
107
146
|
* Build a full KMS key resource name from components.
|
|
108
147
|
*/
|
|
109
148
|
async function buildGCPKMSKeyName(config) {
|
|
110
|
-
var _cryptoKey$primary$na, _cryptoKey$primary;
|
|
111
149
|
let lookupVersion = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
112
|
-
|
|
113
|
-
if (config.versionId) {
|
|
114
|
-
return `${base}/cryptoKeyVersions/${config.versionId}`;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/*
|
|
118
|
-
* Just omit the version if it's not requested
|
|
119
|
-
*/
|
|
120
|
-
if (!lookupVersion) {
|
|
121
|
-
return base;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/*
|
|
125
|
-
* If the versionID is missing, get the latest
|
|
126
|
-
* version from KMS.
|
|
127
|
-
*/
|
|
128
|
-
const client = new packages.KeyManagementServiceClient({
|
|
129
|
-
projectId: config.projectId
|
|
130
|
-
});
|
|
131
|
-
const [cryptoKey] = await client.getCryptoKey({
|
|
132
|
-
name: base
|
|
133
|
-
});
|
|
134
|
-
const latestVersionNumber = (_cryptoKey$primary$na = (_cryptoKey$primary = cryptoKey.primary) === null || _cryptoKey$primary === void 0 || (_cryptoKey$primary = _cryptoKey$primary.name) === null || _cryptoKey$primary === void 0 ? void 0 : _cryptoKey$primary.split('/').at(-1)) !== null && _cryptoKey$primary$na !== void 0 ? _cryptoKey$primary$na : '1';
|
|
135
|
-
return `${base}/cryptoKeyVersions/${latestVersionNumber}`;
|
|
150
|
+
return await buildGCPKMSKeyNameBase(packages.KeyManagementServiceClient, config, lookupVersion);
|
|
136
151
|
}
|
|
137
152
|
|
|
138
153
|
/**
|
|
@@ -303,8 +318,6 @@ function KeetaGCPKMSKeyPairFactory(packages) {
|
|
|
303
318
|
}
|
|
304
319
|
/** @internal */
|
|
305
320
|
_defineProperty(KeetaGCPKMSKeyPair, "_Testing", {
|
|
306
|
-
parseKeyName: parseGCPKMSKeyName,
|
|
307
|
-
buildKeyName: buildGCPKMSKeyName,
|
|
308
321
|
extractPublicKeyFromPem: extractPublicKeyFromPem,
|
|
309
322
|
derSignatureToRaw: derSignatureToRaw
|
|
310
323
|
});
|