@agnostack/next-shopify 1.15.0-beta.16 → 1.15.0-beta.18
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/CHANGELOG.md +16 -0
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +1 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/shared/WebCrypto.d.ts +55 -0
- package/dist/shared/WebCrypto.d.ts.map +1 -0
- package/dist/shared/WebCrypto.js +331 -0
- package/dist/shared/WebCrypto.js.map +1 -0
- package/dist/shared/index.d.ts +1 -1
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +6 -1
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/verification.d.ts +5 -3
- package/dist/shared/verification.d.ts.map +1 -1
- package/dist/shared/verification.js +15 -9
- package/dist/shared/verification.js.map +1 -1
- package/dist/umd/lib/index.d.ts +1 -0
- package/dist/umd/lib/index.d.ts.map +1 -1
- package/dist/umd/shared/WebCrypto.d.ts +55 -0
- package/dist/umd/shared/WebCrypto.d.ts.map +1 -0
- package/dist/umd/shared/index.d.ts +1 -1
- package/dist/umd/shared/index.d.ts.map +1 -1
- package/dist/umd/shared/verification.d.ts +5 -3
- package/dist/umd/shared/verification.d.ts.map +1 -1
- package/dist/umd/verification/utils/rawbody.d.ts.map +1 -1
- package/dist/umd/verification/verification.d.ts +2 -1
- package/dist/umd/verification/verification.d.ts.map +1 -1
- package/dist/umd/verification.js +332 -327
- package/dist/umd/verification.js.map +1 -1
- package/dist/verification/utils/rawbody.d.ts.map +1 -1
- package/dist/verification/utils/rawbody.js +0 -1
- package/dist/verification/utils/rawbody.js.map +1 -1
- package/dist/verification/verification.d.ts +2 -1
- package/dist/verification/verification.d.ts.map +1 -1
- package/dist/verification/verification.js +64 -58
- package/dist/verification/verification.js.map +1 -1
- package/package.json +1 -6
- package/dist/shared/subtlecrypto.d.ts +0 -41
- package/dist/shared/subtlecrypto.d.ts.map +0 -1
- package/dist/shared/subtlecrypto.js +0 -294
- package/dist/shared/subtlecrypto.js.map +0 -1
- package/dist/umd/plugins.js +0 -807
- package/dist/umd/plugins.js.map +0 -1
- package/dist/umd/shared/subtlecrypto.d.ts +0 -41
- package/dist/umd/shared/subtlecrypto.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
# [1.15.0-beta.18](https://github.com/agnostack/next-shopify/compare/v1.15.0-beta.17...v1.15.0-beta.18) (2023-12-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* wip ([1343a5c](https://github.com/agnostack/next-shopify/commit/1343a5c91e53b9cb228376281fe74b711c70b76b))
|
|
7
|
+
|
|
8
|
+
# [1.15.0-beta.17](https://github.com/agnostack/next-shopify/compare/v1.15.0-beta.16...v1.15.0-beta.17) (2023-12-08)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* wip ([d64b8b6](https://github.com/agnostack/next-shopify/commit/d64b8b67f27fe85737fbe3d91a9fcda4b2f5dd2c))
|
|
14
|
+
* wip ([7fdab0b](https://github.com/agnostack/next-shopify/commit/7fdab0bf556c2a42cfd02c300070bec28e64e6ff))
|
|
15
|
+
* wip ([184b9a3](https://github.com/agnostack/next-shopify/commit/184b9a34cf9aec415dd68405b90d29dd397631f4))
|
|
16
|
+
|
|
1
17
|
# [1.15.0-beta.16](https://github.com/agnostack/next-shopify/compare/v1.15.0-beta.15...v1.15.0-beta.16) (2023-12-08)
|
|
2
18
|
|
|
3
19
|
|
package/dist/lib/index.d.ts
CHANGED
package/dist/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA;AAC1B,OAAO,EACL,iBAAiB,EACjB,cAAc,EACf,MAAM,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,OAAO,EACL,iBAAiB,EACjB,cAAc,EACf,MAAM,SAAS,CAAA"}
|
package/dist/lib/index.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.prepareHeaders = exports.getShopifyHelpers = void 0;
|
|
18
18
|
__exportStar(require("../shared"), exports);
|
|
19
19
|
__exportStar(require("../verification"), exports);
|
|
20
|
+
__exportStar(require("../plugins"), exports);
|
|
20
21
|
__exportStar(require("./handlers"), exports);
|
|
21
22
|
var utils_1 = require("./utils");
|
|
22
23
|
Object.defineProperty(exports, "getShopifyHelpers", { enumerable: true, get: function () { return utils_1.getShopifyHelpers; } });
|
package/dist/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4CAAyB;AACzB,kDAA+B;AAC/B,6CAA0B;AAC1B,iCAGgB;AAFd,0GAAA,iBAAiB,OAAA;AACjB,uGAAA,cAAc,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4CAAyB;AACzB,kDAA+B;AAC/B,6CAA0B;AAC1B,6CAA0B;AAC1B,iCAGgB;AAFd,0GAAA,iBAAiB,OAAA;AACjB,uGAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export default WebCrypto;
|
|
2
|
+
declare class WebCrypto {
|
|
3
|
+
constructor({ crypto: _crypto, utils: _util }?: {
|
|
4
|
+
crypto: any;
|
|
5
|
+
utils: any;
|
|
6
|
+
});
|
|
7
|
+
_crypto: any;
|
|
8
|
+
_util: any;
|
|
9
|
+
get subtle(): any;
|
|
10
|
+
getWebCrypto(): Promise<any>;
|
|
11
|
+
getTextDecoder(): Promise<any>;
|
|
12
|
+
getTextEncoder(): Promise<any>;
|
|
13
|
+
timingSafeEqual(value1: any, value2: any): boolean;
|
|
14
|
+
stringToHex(stringValue: any): string;
|
|
15
|
+
hexToString(hexValue: any): string;
|
|
16
|
+
arrayBufferToString(arrayBuffer: any): Promise<any>;
|
|
17
|
+
arrayToArrayBuffer(array: any): any;
|
|
18
|
+
ensureArrayBuffer(arrayOrArrayBuffer: any): any;
|
|
19
|
+
generateKeyPair(): Promise<any>;
|
|
20
|
+
getKeyOperations(keyType: any): string[];
|
|
21
|
+
getKeyAlgorythm(keyType: any): {
|
|
22
|
+
name: string;
|
|
23
|
+
namedCurve?: undefined;
|
|
24
|
+
} | {
|
|
25
|
+
name: string;
|
|
26
|
+
namedCurve: string;
|
|
27
|
+
};
|
|
28
|
+
generateHMAC(message: any, derivedKey: any): Promise<string | undefined>;
|
|
29
|
+
verifyHMAC(message: any, derivedKey: any, verifiableHMAC: any): Promise<boolean>;
|
|
30
|
+
getStorableKey(key: any): Promise<string>;
|
|
31
|
+
restoreStorableKey(keyType: any, storableHex: any): Promise<any>;
|
|
32
|
+
getStorableKeyPair(keyPair: any): Promise<{}>;
|
|
33
|
+
restoreStorableKeyPair(keyPair: any): Promise<{}>;
|
|
34
|
+
deriveSharedKey({ publicKey, privateKey }: {
|
|
35
|
+
publicKey: any;
|
|
36
|
+
privateKey: any;
|
|
37
|
+
}): Promise<any>;
|
|
38
|
+
deriveHMACKey({ publicKey, privateKey }: {
|
|
39
|
+
publicKey: any;
|
|
40
|
+
privateKey: any;
|
|
41
|
+
}): Promise<any>;
|
|
42
|
+
getVerificationKeys({ publicKey, privateKey }: {
|
|
43
|
+
publicKey: any;
|
|
44
|
+
privateKey: any;
|
|
45
|
+
}): Promise<{
|
|
46
|
+
derivedSecretKey?: undefined;
|
|
47
|
+
derivedHMACKey?: undefined;
|
|
48
|
+
} | {
|
|
49
|
+
derivedSecretKey: any;
|
|
50
|
+
derivedHMACKey: any;
|
|
51
|
+
}>;
|
|
52
|
+
encryptMessage(decryptedMessage: any, derivedKey: any): Promise<number[] | undefined>;
|
|
53
|
+
decryptMessage(encryptedMessage: any, derivedKey: any): Promise<any>;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=WebCrypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebCrypto.d.ts","sourceRoot":"","sources":["../../src/shared/WebCrypto.js"],"names":[],"mappings":";AAIA;IACE;;;OAGC;IAFC,aAAsB;IACtB,WAAkB;IAGpB,kBAEC;IAED,6BAoBC;IAED,+BAYC;IAED,+BAYC;IAED,mDAiBC;IAED,sCAMC;IAED,mCAQC;IAED,oDAIC;IAED,oCAMC;IAED,gDAMC;IAED,gCAYC;IAED,yCAiBC;IAED;;;;;;MAmBC;IAED,yEAiBC;IAED,iFAIC;IAED,0CAKC;IAED,iEAkBC;IAED,8CAUC;IAED,kDAUC;IAED;;;qBAoBC;IAED;;;qBAqBC;IAED;;;;;;;;;OAaC;IAED,sFAuBC;IAED,qEAuBC;CACF"}
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
const browser_monads_ts_1 = require("browser-monads-ts");
|
|
36
|
+
const display_1 = require("./display");
|
|
37
|
+
class WebCrypto {
|
|
38
|
+
constructor({ crypto: _crypto, utils: _util } = {}) {
|
|
39
|
+
this._crypto = _crypto;
|
|
40
|
+
this._util = _util;
|
|
41
|
+
}
|
|
42
|
+
get subtle() {
|
|
43
|
+
var _a;
|
|
44
|
+
return (_a = this._crypto) === null || _a === void 0 ? void 0 : _a.subtle;
|
|
45
|
+
}
|
|
46
|
+
getWebCrypto() {
|
|
47
|
+
var _a;
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
if (!this._crypto) {
|
|
50
|
+
try {
|
|
51
|
+
this._crypto = (yield Promise.resolve().then(() => __importStar(require('isomorphic-webcrypto')))).default;
|
|
52
|
+
}
|
|
53
|
+
catch (_ignore) {
|
|
54
|
+
console.info('Failed to import isomorphic-webcrypto, retrying w/ node crypto');
|
|
55
|
+
try {
|
|
56
|
+
this._crypto = (yield Promise.resolve().then(() => __importStar(require('crypto')))).default;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error('Failed to import node crypto');
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (!((_a = this._crypto) === null || _a === void 0 ? void 0 : _a.subtle)) {
|
|
65
|
+
throw new Error('Invalid crypto, missing subtle');
|
|
66
|
+
}
|
|
67
|
+
return this._crypto;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
getTextDecoder() {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
if ((0, browser_monads_ts_1.exists)(browser_monads_ts_1.window) && typeof (browser_monads_ts_1.window === null || browser_monads_ts_1.window === void 0 ? void 0 : browser_monads_ts_1.window.TextDecoder) === 'function') {
|
|
73
|
+
return browser_monads_ts_1.window.TextDecoder;
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const TextDecoder = (this._util || (yield Promise.resolve().then(() => __importStar(require('util'))))).TextDecoder;
|
|
77
|
+
return TextDecoder;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.error('Failed to import utils.TextDecoder', error);
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
getTextEncoder() {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
if ((0, browser_monads_ts_1.exists)(browser_monads_ts_1.window) && typeof (browser_monads_ts_1.window === null || browser_monads_ts_1.window === void 0 ? void 0 : browser_monads_ts_1.window.TextEncoder) === 'function') {
|
|
88
|
+
return browser_monads_ts_1.window.TextEncoder;
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
const TextEncoder = (this._util || (yield Promise.resolve().then(() => __importStar(require('util'))))).TextEncoder;
|
|
92
|
+
return TextEncoder;
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
console.error('Failed to import utils.TextEncoder', error);
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
timingSafeEqual(value1, value2) {
|
|
101
|
+
if ((value1 == undefined) ||
|
|
102
|
+
(value2 == undefined) ||
|
|
103
|
+
(value1.length !== value2.length)) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
let result = 0;
|
|
107
|
+
// eslint-disable-next-line no-plusplus
|
|
108
|
+
for (let i = 0; i < value1.length; i++) {
|
|
109
|
+
// eslint-disable-next-line no-bitwise
|
|
110
|
+
result |= value1[i] ^ value2[i];
|
|
111
|
+
}
|
|
112
|
+
return (result === 0);
|
|
113
|
+
}
|
|
114
|
+
stringToHex(stringValue) {
|
|
115
|
+
return (Array.from((0, display_1.ensureString)(stringValue), (char) => (char.charCodeAt(0).toString(16).padStart(2, '0'))).join(''));
|
|
116
|
+
}
|
|
117
|
+
hexToString(hexValue) {
|
|
118
|
+
return ((0, display_1.ensureArray)((0, display_1.ensureString)(hexValue).match(/.{1,2}/g))
|
|
119
|
+
.map((byte) => String.fromCharCode(parseInt(byte, 16)))
|
|
120
|
+
.join(''));
|
|
121
|
+
}
|
|
122
|
+
arrayBufferToString(arrayBuffer) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
const uint8Array = new Uint8Array(arrayBuffer);
|
|
125
|
+
const Decoder = yield this.getTextDecoder();
|
|
126
|
+
return new Decoder().decode(uint8Array);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
arrayToArrayBuffer(array) {
|
|
130
|
+
return ((ArrayBuffer.from != undefined)
|
|
131
|
+
? ArrayBuffer.from(array)
|
|
132
|
+
: new Uint8Array(array).buffer);
|
|
133
|
+
}
|
|
134
|
+
ensureArrayBuffer(arrayOrArrayBuffer) {
|
|
135
|
+
return ((arrayOrArrayBuffer instanceof ArrayBuffer)
|
|
136
|
+
? arrayOrArrayBuffer
|
|
137
|
+
: this.arrayToArrayBuffer(arrayOrArrayBuffer));
|
|
138
|
+
}
|
|
139
|
+
generateKeyPair() {
|
|
140
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
const crypto = yield this.getWebCrypto();
|
|
142
|
+
const keyPair = yield crypto.subtle.generateKey({
|
|
143
|
+
name: 'ECDH',
|
|
144
|
+
namedCurve: 'P-256',
|
|
145
|
+
}, true, ['deriveKey']);
|
|
146
|
+
return keyPair;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
getKeyOperations(keyType) {
|
|
150
|
+
switch (keyType) {
|
|
151
|
+
case 'private':
|
|
152
|
+
case 'privateKey': {
|
|
153
|
+
return ['deriveKey'];
|
|
154
|
+
}
|
|
155
|
+
case 'secret':
|
|
156
|
+
case 'secretKey':
|
|
157
|
+
case 'sharedSecret': {
|
|
158
|
+
return ['encrypt', 'decrypt'];
|
|
159
|
+
}
|
|
160
|
+
default: {
|
|
161
|
+
return [];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
getKeyAlgorythm(keyType) {
|
|
166
|
+
switch (keyType) {
|
|
167
|
+
case 'derivedKey':
|
|
168
|
+
case 'derived':
|
|
169
|
+
case 'secret':
|
|
170
|
+
case 'secretKey':
|
|
171
|
+
case 'sharedSecret': {
|
|
172
|
+
return {
|
|
173
|
+
name: 'AES-GCM',
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
default: {
|
|
177
|
+
return {
|
|
178
|
+
name: 'ECDH',
|
|
179
|
+
namedCurve: 'P-256',
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
generateHMAC(message, derivedKey) {
|
|
185
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
+
if (!message || !derivedKey) {
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
const crypto = yield this.getWebCrypto();
|
|
190
|
+
const Encoder = yield this.getTextEncoder();
|
|
191
|
+
const signature = yield crypto.subtle.sign('HMAC', derivedKey, new Encoder().encode(message));
|
|
192
|
+
return this.stringToHex(this.arrayBufferToString(signature));
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
verifyHMAC(message, derivedKey, verifiableHMAC) {
|
|
196
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
197
|
+
const calculatedHMAC = yield this.generateHMAC(message, derivedKey);
|
|
198
|
+
return this.timingSafeEqual(calculatedHMAC, verifiableHMAC);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
getStorableKey(key) {
|
|
202
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
203
|
+
const crypto = yield this.getWebCrypto();
|
|
204
|
+
const exportedJWK = yield crypto.subtle.exportKey('jwk', key);
|
|
205
|
+
return this.stringToHex(JSON.stringify(exportedJWK));
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
restoreStorableKey(keyType, storableHex) {
|
|
209
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
210
|
+
if (!storableHex) {
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
213
|
+
const crypto = yield this.getWebCrypto();
|
|
214
|
+
const exportedJWK = JSON.parse(this.hexToString(storableHex) || '{}');
|
|
215
|
+
if ((0, display_1.objectEmpty)(exportedJWK)) {
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
return crypto.subtle.importKey('jwk', exportedJWK, this.getKeyAlgorythm(keyType), true, this.getKeyOperations(keyType));
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
getStorableKeyPair(keyPair) {
|
|
222
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
223
|
+
const storableKeys = {};
|
|
224
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
225
|
+
for (const [keyType, key] of Object.entries(keyPair)) {
|
|
226
|
+
// eslint-disable-next-line no-await-in-loop
|
|
227
|
+
storableKeys[keyType] = yield this.getStorableKey(key);
|
|
228
|
+
}
|
|
229
|
+
return storableKeys;
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
restoreStorableKeyPair(keyPair) {
|
|
233
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
234
|
+
const restoredKeys = {};
|
|
235
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
236
|
+
for (const [keyType, key] of Object.entries(keyPair)) {
|
|
237
|
+
// eslint-disable-next-line no-await-in-loop
|
|
238
|
+
restoredKeys[keyType] = yield this.restoreStorableKey(keyType, key);
|
|
239
|
+
}
|
|
240
|
+
return restoredKeys;
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
deriveSharedKey({ publicKey, privateKey }) {
|
|
244
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
if (!publicKey || !privateKey) {
|
|
246
|
+
return undefined;
|
|
247
|
+
}
|
|
248
|
+
const crypto = yield this.getWebCrypto();
|
|
249
|
+
const derivedKey = yield crypto.subtle.deriveKey({
|
|
250
|
+
name: 'ECDH',
|
|
251
|
+
public: publicKey,
|
|
252
|
+
}, privateKey, {
|
|
253
|
+
name: 'AES-GCM',
|
|
254
|
+
length: 256,
|
|
255
|
+
}, true, ['encrypt', 'decrypt']);
|
|
256
|
+
return derivedKey;
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
deriveHMACKey({ publicKey, privateKey }) {
|
|
260
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
261
|
+
if (!publicKey || !privateKey) {
|
|
262
|
+
return undefined;
|
|
263
|
+
}
|
|
264
|
+
const crypto = yield this.getWebCrypto();
|
|
265
|
+
const derivedKey = yield crypto.subtle.deriveKey({
|
|
266
|
+
name: 'ECDH',
|
|
267
|
+
public: publicKey,
|
|
268
|
+
}, privateKey, {
|
|
269
|
+
name: 'HMAC',
|
|
270
|
+
hash: { name: 'SHA-256' },
|
|
271
|
+
length: 256, // Adjusted key length, e.g., 128 bits
|
|
272
|
+
}, true, ['sign', 'verify']);
|
|
273
|
+
return derivedKey;
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
getVerificationKeys({ publicKey, privateKey }) {
|
|
277
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
278
|
+
if (!publicKey || !privateKey) {
|
|
279
|
+
return {};
|
|
280
|
+
}
|
|
281
|
+
const sharedKeyPair = yield this.restoreStorableKeyPair({ publicKey, privateKey });
|
|
282
|
+
const derivedHMACKey = yield this.deriveHMACKey(sharedKeyPair);
|
|
283
|
+
const derivedSecretKey = yield this.deriveSharedKey(sharedKeyPair);
|
|
284
|
+
return {
|
|
285
|
+
derivedSecretKey,
|
|
286
|
+
derivedHMACKey,
|
|
287
|
+
};
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
encryptMessage(decryptedMessage, derivedKey) {
|
|
291
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
292
|
+
if (!decryptedMessage || !derivedKey) {
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
const crypto = yield this.getWebCrypto();
|
|
296
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
297
|
+
const Encoder = yield this.getTextEncoder();
|
|
298
|
+
const encodedMessage = new Encoder().encode(decryptedMessage);
|
|
299
|
+
const ciphertext = yield crypto.subtle.encrypt({
|
|
300
|
+
name: 'AES-GCM',
|
|
301
|
+
iv,
|
|
302
|
+
}, derivedKey, encodedMessage);
|
|
303
|
+
const encryptedMessage = new Uint8Array([
|
|
304
|
+
...iv,
|
|
305
|
+
...new Uint8Array(ciphertext)
|
|
306
|
+
]);
|
|
307
|
+
return Array.from(encryptedMessage);
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
decryptMessage(encryptedMessage, derivedKey) {
|
|
311
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
312
|
+
if (!encryptedMessage || !derivedKey) {
|
|
313
|
+
return undefined;
|
|
314
|
+
}
|
|
315
|
+
const crypto = yield this.getWebCrypto();
|
|
316
|
+
// NOTE: this presumed an array or arrayBuffer coming in as encryptedMessage (will fail w/ IV error if its a string)
|
|
317
|
+
const encryptedArrayBuffer = this.ensureArrayBuffer(encryptedMessage);
|
|
318
|
+
const iv = encryptedArrayBuffer.slice(0, 12);
|
|
319
|
+
const ciphertext = encryptedArrayBuffer.slice(12);
|
|
320
|
+
const decryptedArrayBuffer = yield crypto.subtle.decrypt({
|
|
321
|
+
name: 'AES-GCM',
|
|
322
|
+
iv,
|
|
323
|
+
}, derivedKey, ciphertext);
|
|
324
|
+
const Decoder = yield this.getTextDecoder();
|
|
325
|
+
const decryptedMessage = new Decoder().decode(decryptedArrayBuffer);
|
|
326
|
+
return decryptedMessage;
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
exports.default = WebCrypto;
|
|
331
|
+
//# sourceMappingURL=WebCrypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebCrypto.js","sourceRoot":"","sources":["../../src/shared/WebCrypto.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAAkD;AAElD,uCAAkE;AAElE,MAAM,SAAS;IACb,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE;QAChD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAED,IAAI,MAAM;;QAC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,CACf,CAAA;YAED,MAAM,gBAAgB,GAAG,IAAI,UAAU,CAAC;gBACtC,GAAG,EAAE;gBACL,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC;aAC9B,CAAC,CAAA;YACF,OAAO,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;QACrC,CAAC;KAAA;IAEK,cAAc,CAAC,gBAAgB,EAAE,UAAU;;YAC/C,IAAI,CAAC,gBAAgB,IAAI,CAAC,UAAU,EAAE;gBACpC,OAAO,SAAS,CAAA;aACjB;YAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,EAAE,CAAA;YACxC,oHAAoH;YACpH,MAAM,oBAAoB,GAAG,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAA;YACrE,MAAM,EAAE,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;YAC5C,MAAM,UAAU,GAAG,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;YAEjD,MAAM,oBAAoB,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CACtD;gBACE,IAAI,EAAE,SAAS;gBACf,EAAE;aACH,EACD,UAAU,EACV,UAAU,CACX,CAAA;YAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,CAAA;YAC3C,MAAM,gBAAgB,GAAG,IAAI,OAAO,EAAE,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAA;YACnE,OAAO,gBAAgB,CAAA;QACzB,CAAC;KAAA;CACF;AAED,kBAAe,SAAS,CAAA"}
|
package/dist/shared/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export * from './graph';
|
|
|
6
6
|
export * from './match';
|
|
7
7
|
export * from './request';
|
|
8
8
|
export * from './shopify';
|
|
9
|
-
export * from './subtlecrypto';
|
|
10
9
|
export * from './uuid';
|
|
11
10
|
export * from './verification';
|
|
11
|
+
export { default as WebCrypto } from './WebCrypto';
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,QAAQ,CAAA;AACtB,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/shared/index.js
CHANGED
|
@@ -13,7 +13,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
16
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.WebCrypto = void 0;
|
|
17
21
|
__exportStar(require("./constants"), exports);
|
|
18
22
|
__exportStar(require("./datetime"), exports);
|
|
19
23
|
__exportStar(require("./display"), exports);
|
|
@@ -22,7 +26,8 @@ __exportStar(require("./graph"), exports);
|
|
|
22
26
|
__exportStar(require("./match"), exports);
|
|
23
27
|
__exportStar(require("./request"), exports);
|
|
24
28
|
__exportStar(require("./shopify"), exports);
|
|
25
|
-
__exportStar(require("./subtlecrypto"), exports);
|
|
26
29
|
__exportStar(require("./uuid"), exports);
|
|
27
30
|
__exportStar(require("./verification"), exports);
|
|
31
|
+
var WebCrypto_1 = require("./WebCrypto");
|
|
32
|
+
Object.defineProperty(exports, "WebCrypto", { enumerable: true, get: function () { return __importDefault(WebCrypto_1).default; } });
|
|
28
33
|
//# sourceMappingURL=index.js.map
|
package/dist/shared/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,8CAA2B;AAC3B,6CAA0B;AAC1B,4CAAyB;AACzB,2CAAwB;AACxB,0CAAuB;AACvB,0CAAuB;AACvB,4CAAyB;AACzB,4CAAyB;AACzB,yCAAsB;AACtB,iDAA8B;AAC9B,yCAAkD;AAAzC,uHAAA,OAAO,OAAa"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function getKeysData(publicKey: any): Promise<{
|
|
1
|
+
export function getKeysData(publicKey: any, _crypto: any): Promise<{
|
|
2
2
|
publicKey: any;
|
|
3
3
|
ephemeral: {};
|
|
4
4
|
verification: {
|
|
@@ -9,16 +9,18 @@ export function getKeysData(publicKey: any): Promise<{
|
|
|
9
9
|
derivedHMACKey: any;
|
|
10
10
|
};
|
|
11
11
|
}>;
|
|
12
|
-
export function prepareVerificationRequest({ keysData: _keysData, disableRecryption: _disableRecryption }?: {
|
|
12
|
+
export function prepareVerificationRequest({ keysData: _keysData, disableRecryption: _disableRecryption, crypto: _crypto }?: {
|
|
13
13
|
keysData: any;
|
|
14
14
|
disableRecryption: any;
|
|
15
|
+
crypto: any;
|
|
15
16
|
}): (requestPath: any, { method: rawMethod, body: rawBody, headers: rawHeaders, ...requestOptions }?: {
|
|
16
17
|
method: any;
|
|
17
18
|
body: any;
|
|
18
19
|
headers: any;
|
|
19
20
|
}) => Promise<any[] | undefined>;
|
|
20
|
-
export function processVerificationResponse({ keysData, disableRecryption: _disableRecryption }?: {
|
|
21
|
+
export function processVerificationResponse({ keysData, disableRecryption: _disableRecryption, crypto: _crypto }?: {
|
|
21
22
|
keysData: any;
|
|
22
23
|
disableRecryption: any;
|
|
24
|
+
crypto: any;
|
|
23
25
|
}): (encryptedResponse: any, _derivedSecretKey: any) => Promise<any>;
|
|
24
26
|
//# sourceMappingURL=verification.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verification.d.ts","sourceRoot":"","sources":["../../src/shared/verification.js"],"names":[],"mappings":"AAKO;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"verification.d.ts","sourceRoot":"","sources":["../../src/shared/verification.js"],"names":[],"mappings":"AAKO;;;;;;;;;;GAiBN;AAGM;;;;;;;;iCAkEN;AAEM;;;;qEAaN"}
|
|
@@ -19,15 +19,19 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
19
19
|
}
|
|
20
20
|
return t;
|
|
21
21
|
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
22
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
26
|
exports.processVerificationResponse = exports.prepareVerificationRequest = exports.getKeysData = void 0;
|
|
24
27
|
const request_1 = require("./request");
|
|
25
28
|
const display_1 = require("./display");
|
|
26
29
|
const datetime_1 = require("./datetime");
|
|
27
|
-
const
|
|
28
|
-
const getKeysData = (publicKey) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
-
const
|
|
30
|
-
const
|
|
30
|
+
const WebCrypto_1 = __importDefault(require("./WebCrypto"));
|
|
31
|
+
const getKeysData = (publicKey, _crypto) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
const webCrypto = new WebCrypto_1.default({ crypto: _crypto });
|
|
33
|
+
const _ephemeralStoreableKeyPair = yield webCrypto.getStorableKeyPair(yield webCrypto.generateKeyPair(publicKey));
|
|
34
|
+
const _verificationKeyPair = yield webCrypto.getVerificationKeys({
|
|
31
35
|
publicKey,
|
|
32
36
|
privateKey: _ephemeralStoreableKeyPair.privateKey,
|
|
33
37
|
});
|
|
@@ -39,7 +43,8 @@ const getKeysData = (publicKey) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
39
43
|
});
|
|
40
44
|
exports.getKeysData = getKeysData;
|
|
41
45
|
// eslint-disable-next-line arrow-body-style
|
|
42
|
-
const prepareVerificationRequest = ({ keysData: _keysData, disableRecryption: _disableRecryption } = {}) => {
|
|
46
|
+
const prepareVerificationRequest = ({ keysData: _keysData, disableRecryption: _disableRecryption, crypto: _crypto } = {}) => {
|
|
47
|
+
const webCrypto = new WebCrypto_1.default({ crypto: _crypto });
|
|
43
48
|
const disableRecryption = (0, display_1.isTrue)(_disableRecryption);
|
|
44
49
|
return (requestPath, _a = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
50
|
var { method: rawMethod, body: rawBody, headers: rawHeaders } = _a, requestOptions = __rest(_a, ["method", "body", "headers"]);
|
|
@@ -56,10 +61,10 @@ const prepareVerificationRequest = ({ keysData: _keysData, disableRecryption: _d
|
|
|
56
61
|
return undefined;
|
|
57
62
|
}
|
|
58
63
|
if (parsedBody && derivedSecretKey) {
|
|
59
|
-
parsedBody = yield
|
|
64
|
+
parsedBody = yield webCrypto.encryptMessage(JSON.stringify(parsedBody), derivedSecretKey);
|
|
60
65
|
}
|
|
61
66
|
const timestamp = (0, datetime_1.toUnixString)();
|
|
62
|
-
const computedHMAC = yield
|
|
67
|
+
const computedHMAC = yield webCrypto.generateHMAC((0, display_1.objectToSortedString)(Object.assign({ body: parsedBody, method,
|
|
63
68
|
timestamp }, (0, request_1.normalizeURIParts)(requestPath))), derivedHMACKey);
|
|
64
69
|
return [
|
|
65
70
|
requestPath,
|
|
@@ -69,7 +74,8 @@ const prepareVerificationRequest = ({ keysData: _keysData, disableRecryption: _d
|
|
|
69
74
|
});
|
|
70
75
|
};
|
|
71
76
|
exports.prepareVerificationRequest = prepareVerificationRequest;
|
|
72
|
-
const processVerificationResponse = ({ keysData, disableRecryption: _disableRecryption } = {}) => {
|
|
77
|
+
const processVerificationResponse = ({ keysData, disableRecryption: _disableRecryption, crypto: _crypto } = {}) => {
|
|
78
|
+
const webCrypto = new WebCrypto_1.default({ crypto: _crypto });
|
|
73
79
|
const disableRecryption = (0, display_1.isTrue)(_disableRecryption);
|
|
74
80
|
return (encryptedResponse, _derivedSecretKey) => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
81
|
var _a;
|
|
@@ -77,7 +83,7 @@ const processVerificationResponse = ({ keysData, disableRecryption: _disableRecr
|
|
|
77
83
|
if (disableRecryption || !encryptedResponse || !derivedSecretKey) {
|
|
78
84
|
return encryptedResponse;
|
|
79
85
|
}
|
|
80
|
-
const decryptedMessage = yield
|
|
86
|
+
const decryptedMessage = yield webCrypto.decryptMessage(encryptedResponse, derivedSecretKey);
|
|
81
87
|
return (0, display_1.safeParse)(decryptedMessage);
|
|
82
88
|
});
|
|
83
89
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verification.js","sourceRoot":"","sources":["../../src/shared/verification.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"verification.js","sourceRoot":"","sources":["../../src/shared/verification.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAsF;AACtF,uCAAgF;AAChF,yCAAyC;AACzC,4DAAmC;AAE5B,MAAM,WAAW,GAAG,CAAO,SAAS,EAAE,OAAO,EAAE,EAAE;IACtD,MAAM,SAAS,GAAG,IAAI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MAAM,SAAS,GAAG,IAAI,mBAAS,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAA;IACpD,MAAM,iBAAiB,GAAG,IAAA,gBAAM,EAAC,kBAAkB,CAAC,CAAA;IAEpD,OAAO,CAAO,iBAAiB,EAAE,iBAAiB,EAAE,EAAE;;QACpD,MAAM,gBAAgB,GAAG,iBAAiB,aAAjB,iBAAiB,cAAjB,iBAAiB,GAAI,MAAA,QAAQ,CAAC,YAAY,0CAAE,gBAAgB,CAAA;QACrF,IAAI,iBAAiB,IAAI,CAAC,iBAAiB,IAAI,CAAC,gBAAgB,EAAE;YAChE,OAAO,iBAAiB,CAAA;SACzB;QAED,MAAM,gBAAgB,GAAG,MAAM,SAAS,CAAC,cAAc,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAA;QAC5F,OAAO,IAAA,mBAAS,EAAC,gBAAgB,CAAC,CAAA;IACpC,CAAC,CAAA,CAAA;AACH,CAAC,CAAA;AAbY,QAAA,2BAA2B,+BAavC"}
|
package/dist/umd/lib/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA;AAC1B,OAAO,EACL,iBAAiB,EACjB,cAAc,EACf,MAAM,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,OAAO,EACL,iBAAiB,EACjB,cAAc,EACf,MAAM,SAAS,CAAA"}
|