@cartridge/controller 0.1.48 → 0.1.51
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/lib/index.d.ts +5 -2
- package/lib/index.js +3 -2
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +6 -2
- package/package.json +1 -1
- package/lib/account.d.ts +0 -58
- package/lib/messenger.d.ts +0 -17
- package/lib/signer.d.ts +0 -38
- package/lib/utils.d.ts +0 -2
- package/lib/webauthn.d.ts +0 -16
- package/lib/webauthn.js +0 -137
- package/lib/webauthn.js.map +0 -1
package/lib/index.d.ts
CHANGED
|
@@ -15,8 +15,11 @@ declare class Controller {
|
|
|
15
15
|
});
|
|
16
16
|
ready(): Promise<boolean | undefined>;
|
|
17
17
|
probe(): Promise<AccountInterface | undefined>;
|
|
18
|
-
register(
|
|
19
|
-
|
|
18
|
+
register(username: string, credential: {
|
|
19
|
+
x: string;
|
|
20
|
+
y: string;
|
|
21
|
+
}): Promise<{
|
|
22
|
+
address: string;
|
|
20
23
|
}>;
|
|
21
24
|
connect(): Promise<AccountInterface | null>;
|
|
22
25
|
}
|
package/lib/index.js
CHANGED
|
@@ -102,13 +102,14 @@ class Controller {
|
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
104
|
// Register a new device key.
|
|
105
|
-
register(
|
|
105
|
+
register(username, credential) {
|
|
106
106
|
var _a;
|
|
107
107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
108
108
|
const register = yield ((_a = this.messenger) === null || _a === void 0 ? void 0 : _a.send({
|
|
109
109
|
method: "register",
|
|
110
110
|
params: {
|
|
111
|
-
|
|
111
|
+
username,
|
|
112
|
+
credential
|
|
112
113
|
}
|
|
113
114
|
}));
|
|
114
115
|
if (!register || register.error) {
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;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CACT,GAAG,IAAI,CAAC,GAAG,YAAY,sBAAE,CAAC,SAAS,CAAC;gBAClC,EAAE;gBACF,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC;aACpC,CAAC,EAAE,EACJ,QAAQ,EACR,sBAAsB,CACvB,CAAC;YAEF,MAAM,QAAQ,GAAG,MAAM,CAAA,MAAA,IAAI,CAAC,SAAS,0CAAE,IAAI,CAAkB;gBAC3D,MAAM,EAAE,SAAS;gBACjB,MAAM,EAAE;oBACN,EAAE;oBACF,MAAM,EAAE,IAAI,CAAC,MAAM;iBACpB;aACgB,CAAC,CAAA,CAAC;YAErB,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,KAAK,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;gBACtE,OAAO,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAA;gBACtC,OAAO,IAAI,CAAC;aACb;YAED,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAO,CACxB,QAAQ,CAAC,MAAM,CAAC,OAAQ,EACxB,QAAQ,CAAC,MAAM,CAAC,MAAM,EACtB,IAAI,CAAC,SAAS,EACd;gBACE,GAAG,EAAE,IAAI,CAAC,GAAG;aACd,CACF,CAAC;YAEF,OAAO,IAAI,CAAC,OAAO,CAAC;;KACrB;CACF;AAED,kBAAe,UAAU,CAAC;AAG1B,0CAAwB"}
|
package/lib/types.d.ts
CHANGED
|
@@ -103,13 +103,17 @@ export interface SignMessageResponse extends RawResponse {
|
|
|
103
103
|
export interface RegisterRequest extends RawRequest {
|
|
104
104
|
method: "register";
|
|
105
105
|
params: {
|
|
106
|
-
|
|
106
|
+
username: string;
|
|
107
|
+
credential: {
|
|
108
|
+
x: string;
|
|
109
|
+
y: string;
|
|
110
|
+
};
|
|
107
111
|
};
|
|
108
112
|
}
|
|
109
113
|
export interface RegisterResponse extends RawResponse {
|
|
110
114
|
method: "register";
|
|
111
115
|
result: {
|
|
112
|
-
|
|
116
|
+
address: string;
|
|
113
117
|
};
|
|
114
118
|
}
|
|
115
119
|
export declare type RawRequest = {
|
package/package.json
CHANGED
package/lib/account.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { Account, DeployContractPayload, Abi, Call, EstimateFeeDetails, EstimateFee, DeployContractResponse as StarknetDeployContractResponse, InvocationsDetails, Signature, typedData, InvokeFunctionResponse } from "starknet";
|
|
2
|
-
import Messenger from "./messenger";
|
|
3
|
-
import { Scope } from "./types";
|
|
4
|
-
declare class CartridgeAccount extends Account {
|
|
5
|
-
address: string;
|
|
6
|
-
private messenger;
|
|
7
|
-
private url;
|
|
8
|
-
private _scopes;
|
|
9
|
-
constructor(address: string, scopes: Scope[] | undefined, messenger: Messenger, options?: {
|
|
10
|
-
url?: string;
|
|
11
|
-
});
|
|
12
|
-
/**
|
|
13
|
-
* Deploys a given compiled contract (json) to starknet
|
|
14
|
-
*
|
|
15
|
-
* @param payload payload to be deployed containing:
|
|
16
|
-
* - compiled contract code
|
|
17
|
-
* - constructor calldata
|
|
18
|
-
* - address salt
|
|
19
|
-
* @param abi the abi of the contract
|
|
20
|
-
* @returns a confirmation of sending a transaction on the starknet contract
|
|
21
|
-
*/
|
|
22
|
-
deployContract(payload: DeployContractPayload, abi?: Abi): Promise<StarknetDeployContractResponse>;
|
|
23
|
-
/**
|
|
24
|
-
* Estimate Fee for a method on starknet
|
|
25
|
-
*
|
|
26
|
-
* @param calls the invocation object containing:
|
|
27
|
-
* - contractAddress - the address of the contract
|
|
28
|
-
* - entrypoint - the entrypoint of the contract
|
|
29
|
-
* - calldata - (defaults to []) the calldata
|
|
30
|
-
* - signature - (defaults to []) the signature
|
|
31
|
-
*
|
|
32
|
-
* @returns response from addTransaction
|
|
33
|
-
*/
|
|
34
|
-
estimateFee(calls: Call | Call[], { nonce: providedNonce, blockIdentifier }?: EstimateFeeDetails): Promise<EstimateFee>;
|
|
35
|
-
/**
|
|
36
|
-
* Invoke execute function in account contract
|
|
37
|
-
*
|
|
38
|
-
* @param calls the invocation object or an array of them, containing:
|
|
39
|
-
* - contractAddress - the address of the contract
|
|
40
|
-
* - entrypoint - the entrypoint of the contract
|
|
41
|
-
* - calldata - (defaults to []) the calldata
|
|
42
|
-
* - signature - (defaults to []) the signature
|
|
43
|
-
* @param abis (optional) the abi of the contract for better displaying
|
|
44
|
-
*
|
|
45
|
-
* @returns response from addTransaction
|
|
46
|
-
*/
|
|
47
|
-
execute(calls: Call | Call[], abis?: Abi[], transactionsDetail?: InvocationsDetails): Promise<InvokeFunctionResponse>;
|
|
48
|
-
/**
|
|
49
|
-
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
50
|
-
* This adds a message prefix so it cant be interchanged with transactions
|
|
51
|
-
*
|
|
52
|
-
* @param json - JSON object to be signed
|
|
53
|
-
* @returns the signature of the JSON object
|
|
54
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
55
|
-
*/
|
|
56
|
-
signMessage(typedData: typedData.TypedData): Promise<Signature>;
|
|
57
|
-
}
|
|
58
|
-
export default CartridgeAccount;
|
package/lib/messenger.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Request, Response } from "./types";
|
|
2
|
-
export declare type Message<T = Request | Response> = {
|
|
3
|
-
id?: string;
|
|
4
|
-
type: "request" | "response";
|
|
5
|
-
target: string;
|
|
6
|
-
payload: T;
|
|
7
|
-
};
|
|
8
|
-
declare class Messenger {
|
|
9
|
-
private target;
|
|
10
|
-
private origin;
|
|
11
|
-
private pending;
|
|
12
|
-
private defaultHandler;
|
|
13
|
-
constructor(target: Window | null, origin?: string);
|
|
14
|
-
onRequest(cb: (request: Request, reply: (response: Response) => void) => void): void;
|
|
15
|
-
send<T = Response>(request: Request): Promise<T>;
|
|
16
|
-
}
|
|
17
|
-
export default Messenger;
|
package/lib/signer.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Abi, Invocation, InvocationsSignerDetails, SignerInterface, Signature, typedData } from "starknet";
|
|
2
|
-
import Messenger from "./messenger";
|
|
3
|
-
export declare class Signer implements SignerInterface {
|
|
4
|
-
private messenger;
|
|
5
|
-
private url;
|
|
6
|
-
constructor(messenger: Messenger, options?: {
|
|
7
|
-
url?: string;
|
|
8
|
-
});
|
|
9
|
-
/**
|
|
10
|
-
* Method to get the public key of the signer
|
|
11
|
-
*
|
|
12
|
-
* @returns public key of signer as hex string with 0x prefix
|
|
13
|
-
*/
|
|
14
|
-
getPubKey(): Promise<string>;
|
|
15
|
-
/**
|
|
16
|
-
* Sign an JSON object for off-chain usage with the starknet private key and return the signature
|
|
17
|
-
* This adds a message prefix so it cant be interchanged with transactions
|
|
18
|
-
*
|
|
19
|
-
* @param typedData - JSON object to be signed
|
|
20
|
-
* @param accountAddress - account
|
|
21
|
-
* @returns the signature of the JSON object
|
|
22
|
-
* @throws {Error} if the JSON object is not a valid JSON
|
|
23
|
-
*/
|
|
24
|
-
signMessage(typedData: typedData.TypedData, account: string): Promise<Signature>;
|
|
25
|
-
/**
|
|
26
|
-
* Signs a transaction with the starknet private key and returns the signature
|
|
27
|
-
*
|
|
28
|
-
* @param invocation the invocation object containing:
|
|
29
|
-
* - contractAddress - the address of the contract
|
|
30
|
-
* - entrypoint - the entrypoint of the contract
|
|
31
|
-
* - calldata - (defaults to []) the calldata
|
|
32
|
-
* - signature - (defaults to []) the signature
|
|
33
|
-
* @param abi (optional) the abi of the contract for better displaying
|
|
34
|
-
*
|
|
35
|
-
* @returns signature
|
|
36
|
-
*/
|
|
37
|
-
signTransaction(transactions: Invocation[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
|
|
38
|
-
}
|
package/lib/utils.d.ts
DELETED
package/lib/webauthn.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Abi, Call, InvocationsSignerDetails, Signature, SignerInterface, typedData } from "starknet";
|
|
2
|
-
declare type Assertion = PublicKeyCredential & {
|
|
3
|
-
response: AuthenticatorAssertionResponse;
|
|
4
|
-
};
|
|
5
|
-
export declare class WebauthnSigner implements SignerInterface {
|
|
6
|
-
private credentialId;
|
|
7
|
-
private publicKey;
|
|
8
|
-
constructor(credentialId: string, publicKey: string);
|
|
9
|
-
getPubKey(): Promise<string>;
|
|
10
|
-
sign(hash: string): Promise<Assertion>;
|
|
11
|
-
formatAssertion(assertion: Assertion): Signature;
|
|
12
|
-
hashTransaction(transactions: Call[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): string;
|
|
13
|
-
signTransaction(calls: Call[], transactionsDetail: InvocationsSignerDetails, abis?: Abi[]): Promise<Signature>;
|
|
14
|
-
signMessage(td: typedData.TypedData, accountAddress: string): Promise<Signature>;
|
|
15
|
-
}
|
|
16
|
-
export {};
|
package/lib/webauthn.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.WebauthnSigner = void 0;
|
|
16
|
-
const starknet_1 = require("starknet");
|
|
17
|
-
const base64url_1 = __importDefault(require("base64url"));
|
|
18
|
-
const BASE = starknet_1.number.toBN(2).pow(86);
|
|
19
|
-
function split(n) {
|
|
20
|
-
const x = n.mod(BASE);
|
|
21
|
-
const y = n.div(BASE).mod(BASE);
|
|
22
|
-
const z = n.div(BASE).div(BASE);
|
|
23
|
-
return { x, y, z };
|
|
24
|
-
}
|
|
25
|
-
function convertUint8ArrayToWordArray(u8Array) {
|
|
26
|
-
var words = [], i = 0, len = u8Array.length;
|
|
27
|
-
while (i < len) {
|
|
28
|
-
words.push(((u8Array[i++] << 24) |
|
|
29
|
-
(u8Array[i++] << 16) |
|
|
30
|
-
(u8Array[i++] << 8) |
|
|
31
|
-
u8Array[i++]) >>>
|
|
32
|
-
0);
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
sigBytes: words.length * 4,
|
|
36
|
-
words: words,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
class WebauthnSigner {
|
|
40
|
-
constructor(credentialId, publicKey) {
|
|
41
|
-
this.credentialId = credentialId;
|
|
42
|
-
this.publicKey = publicKey;
|
|
43
|
-
}
|
|
44
|
-
getPubKey() {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
return this.publicKey;
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
sign(hash) {
|
|
50
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
const challenge = Buffer.from(hash.slice(2).padStart(64, "0").slice(0, 64), "hex");
|
|
52
|
-
return (yield navigator.credentials.get({
|
|
53
|
-
publicKey: {
|
|
54
|
-
challenge,
|
|
55
|
-
timeout: 60000,
|
|
56
|
-
rpId: "cartridge.gg",
|
|
57
|
-
allowCredentials: [
|
|
58
|
-
{
|
|
59
|
-
type: "public-key",
|
|
60
|
-
id: base64url_1.default.toBuffer(this.credentialId),
|
|
61
|
-
},
|
|
62
|
-
],
|
|
63
|
-
userVerification: "required",
|
|
64
|
-
},
|
|
65
|
-
}));
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
formatAssertion(assertion) {
|
|
69
|
-
var authenticatorDataBytes = new Uint8Array(assertion.response.authenticatorData);
|
|
70
|
-
let authenticatorDataRem = 4 - (authenticatorDataBytes.length % 4);
|
|
71
|
-
if (authenticatorDataRem == 4) {
|
|
72
|
-
authenticatorDataRem = 0;
|
|
73
|
-
}
|
|
74
|
-
const authenticatorDataWords = convertUint8ArrayToWordArray(authenticatorDataBytes).words;
|
|
75
|
-
var clientDataJSONBytes = new Uint8Array(assertion.response.clientDataJSON);
|
|
76
|
-
let clientDataJSONRem = 4 - (clientDataJSONBytes.length % 4);
|
|
77
|
-
if (clientDataJSONRem == 4) {
|
|
78
|
-
clientDataJSONRem = 0;
|
|
79
|
-
}
|
|
80
|
-
const clientDataWords = convertUint8ArrayToWordArray(clientDataJSONBytes).words;
|
|
81
|
-
// Convert signature from ASN.1 sequence to "raw" format
|
|
82
|
-
const usignature = new Uint8Array(assertion.response.signature);
|
|
83
|
-
const rStart = usignature[4] === 0 ? 5 : 4;
|
|
84
|
-
const rEnd = rStart + 32;
|
|
85
|
-
const sStart = usignature[rEnd + 2] === 0 ? rEnd + 3 : rEnd + 2;
|
|
86
|
-
const r = starknet_1.number.toBN("0x" + Buffer.from(usignature.slice(rStart, rEnd)).toString("hex"));
|
|
87
|
-
const s = starknet_1.number.toBN("0x" + Buffer.from(usignature.slice(sStart)).toString("hex"));
|
|
88
|
-
const { x: r0, y: r1, z: r2 } = split(r);
|
|
89
|
-
const { x: s0, y: s1, z: s2 } = split(s);
|
|
90
|
-
return [
|
|
91
|
-
"0",
|
|
92
|
-
r0.toString(),
|
|
93
|
-
r1.toString(),
|
|
94
|
-
r2.toString(),
|
|
95
|
-
s0.toString(),
|
|
96
|
-
s1.toString(),
|
|
97
|
-
s2.toString(),
|
|
98
|
-
"9",
|
|
99
|
-
"0",
|
|
100
|
-
`${clientDataWords.length}`,
|
|
101
|
-
`${clientDataJSONRem}`,
|
|
102
|
-
...clientDataWords.map((word) => `${word}`),
|
|
103
|
-
`${authenticatorDataWords.length}`,
|
|
104
|
-
`${authenticatorDataRem}`,
|
|
105
|
-
...authenticatorDataWords.map((word) => `${word}`),
|
|
106
|
-
];
|
|
107
|
-
}
|
|
108
|
-
hashTransaction(transactions, transactionsDetail, abis) {
|
|
109
|
-
if (abis && abis.length !== transactions.length) {
|
|
110
|
-
throw new Error("ABI must be provided for each transaction or no transaction");
|
|
111
|
-
}
|
|
112
|
-
// now use abi to display decoded data somewhere, but as this signer is headless, we can't do that
|
|
113
|
-
const calldata = starknet_1.transaction.fromCallsToExecuteCalldataWithNonce(transactions, transactionsDetail.nonce);
|
|
114
|
-
return starknet_1.hash.calculateTransactionHash(transactionsDetail.walletAddress, transactionsDetail.version, [starknet_1.hash.getSelectorFromName("__execute__")].concat(calldata), transactionsDetail.maxFee, transactionsDetail.chainId, transactionsDetail.nonce);
|
|
115
|
-
}
|
|
116
|
-
signTransaction(calls, transactionsDetail, abis) {
|
|
117
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
-
if (abis && abis.length !== calls.length) {
|
|
119
|
-
throw new Error("ABI must be provided for each transaction or no transaction");
|
|
120
|
-
}
|
|
121
|
-
// now use abi to display decoded data somewhere, but as this signer is headless, we can't do that
|
|
122
|
-
const calldata = starknet_1.transaction.fromCallsToExecuteCalldataWithNonce(calls, transactionsDetail.nonce);
|
|
123
|
-
const msgHash = starknet_1.hash.calculateTransactionHash(transactionsDetail.walletAddress, transactionsDetail.version, [starknet_1.hash.getSelectorFromName("__execute__")].concat(calldata), transactionsDetail.maxFee, transactionsDetail.chainId, transactionsDetail.nonce);
|
|
124
|
-
const assertion = yield this.sign(msgHash);
|
|
125
|
-
return this.formatAssertion(assertion);
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
signMessage(td, accountAddress) {
|
|
129
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
-
const msgHash = starknet_1.typedData.getMessageHash(td, accountAddress);
|
|
131
|
-
const assertion = yield this.sign(msgHash);
|
|
132
|
-
return this.formatAssertion(assertion);
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
exports.WebauthnSigner = WebauthnSigner;
|
|
137
|
-
//# sourceMappingURL=webauthn.js.map
|
package/lib/webauthn.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"webauthn.js","sourceRoot":"","sources":["../src/webauthn.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAUkB;AAClB,0DAAkC;AAGlC,MAAM,IAAI,GAAG,iBAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAMpC,SAAS,KAAK,CAAC,CAAe;IAC5B,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACtB,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AACrB,CAAC;AAED,SAAS,4BAA4B,CAAC,OAAmB;IACvD,IAAI,KAAK,GAAG,EAAE,EACZ,CAAC,GAAG,CAAC,EACL,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAEvB,OAAO,CAAC,GAAG,GAAG,EAAE;QACd,KAAK,CAAC,IAAI,CACR,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;YACnB,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;YACpB,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;YACnB,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;YACf,CAAC,CACF,CAAC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