@plainkey/browser 0.3.3 → 0.3.5
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/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +14 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -16,7 +16,8 @@ declare class PlainKeyClient {
|
|
|
16
16
|
Registration(beginParams: RegistrationBeginRequest): Promise<RegistrationCompleteResponse>;
|
|
17
17
|
/**
|
|
18
18
|
* Add credential to existing user.
|
|
19
|
-
* Requires valid user authentication token
|
|
19
|
+
* Requires a valid user authentication token passed in beginParams, which will be sent in the request body.
|
|
20
|
+
* However, do not store the token in local storage, database, etc. Always keep it in memory.
|
|
20
21
|
*/
|
|
21
22
|
AddCredential(beginParams: UserCredentialBeginRequest): Promise<UserCredentialCompleteResponse>;
|
|
22
23
|
/**
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/plainkey-client.ts"],"sourcesContent":[],"mappings":";;;KAsBY,oBAAA;EAAA,SAAA,EAAA,MAAA;EAMC,OAAA,CAAA,EAAA,MAAA;CAAc;AAIC,cAJf,cAAA,CAIe;mBAWM,SAAA;mBAAmC,OAAA;aAAR,CAAA,YAAA,EAXjC,oBAWiC;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/plainkey-client.ts"],"sourcesContent":[],"mappings":";;;KAsBY,oBAAA;EAAA,SAAA,EAAA,MAAA;EAMC,OAAA,CAAA,EAAA,MAAA;CAAc;AAIC,cAJf,cAAA,CAIe;mBAWM,SAAA;mBAAmC,OAAA;aAAR,CAAA,YAAA,EAXjC,oBAWiC;;;;;cA+GN,CAAA,WAAA,EA/GrB,wBA+GqB,CAAA,EA/GM,OA+GN,CA/Gc,4BA+Gd,CAAA;;;;;;6BAvDtC,6BACZ,QAAQ;;;;qBAsDc,oBAAoB,QAAQ"}
|
package/dist/index.mjs
CHANGED
|
@@ -12,14 +12,12 @@ var PlainKeyClient = class {
|
|
|
12
12
|
* Creates a new user and adds a credential to it.
|
|
13
13
|
*/
|
|
14
14
|
async Registration(beginParams) {
|
|
15
|
-
const headers = new Headers({
|
|
16
|
-
"Content-Type": "application/json",
|
|
17
|
-
"x-project-id": this.projectId
|
|
18
|
-
});
|
|
19
15
|
const beginResponse = await fetch(`${this.baseUrl}/user/register/begin`, {
|
|
20
16
|
method: "POST",
|
|
21
|
-
headers
|
|
22
|
-
|
|
17
|
+
headers: {
|
|
18
|
+
"Content-Type": "application/json",
|
|
19
|
+
"x-project-id": this.projectId
|
|
20
|
+
},
|
|
23
21
|
body: JSON.stringify(beginParams)
|
|
24
22
|
});
|
|
25
23
|
if (!beginResponse.ok) {
|
|
@@ -38,7 +36,6 @@ var PlainKeyClient = class {
|
|
|
38
36
|
"Content-Type": "application/json",
|
|
39
37
|
"x-project-id": this.projectId
|
|
40
38
|
},
|
|
41
|
-
credentials: "include",
|
|
42
39
|
body: JSON.stringify(completeParams)
|
|
43
40
|
});
|
|
44
41
|
if (!completeResponse.ok) {
|
|
@@ -51,17 +48,16 @@ var PlainKeyClient = class {
|
|
|
51
48
|
}
|
|
52
49
|
/**
|
|
53
50
|
* Add credential to existing user.
|
|
54
|
-
* Requires valid user authentication token
|
|
51
|
+
* Requires a valid user authentication token passed in beginParams, which will be sent in the request body.
|
|
52
|
+
* However, do not store the token in local storage, database, etc. Always keep it in memory.
|
|
55
53
|
*/
|
|
56
54
|
async AddCredential(beginParams) {
|
|
57
|
-
const headers = new Headers({
|
|
58
|
-
"Content-Type": "application/json",
|
|
59
|
-
"x-project-id": this.projectId
|
|
60
|
-
});
|
|
61
55
|
const beginResponse = await fetch(`${this.baseUrl}/user/credential/begin`, {
|
|
62
56
|
method: "POST",
|
|
63
|
-
headers
|
|
64
|
-
|
|
57
|
+
headers: {
|
|
58
|
+
"Content-Type": "application/json",
|
|
59
|
+
"x-project-id": this.projectId
|
|
60
|
+
},
|
|
65
61
|
body: JSON.stringify(beginParams)
|
|
66
62
|
});
|
|
67
63
|
if (!beginResponse.ok) {
|
|
@@ -80,7 +76,6 @@ var PlainKeyClient = class {
|
|
|
80
76
|
"Content-Type": "application/json",
|
|
81
77
|
"x-project-id": this.projectId
|
|
82
78
|
},
|
|
83
|
-
credentials: "include",
|
|
84
79
|
body: JSON.stringify(completeParams)
|
|
85
80
|
});
|
|
86
81
|
if (!completeResponse.ok) {
|
|
@@ -101,7 +96,6 @@ var PlainKeyClient = class {
|
|
|
101
96
|
"Content-Type": "application/json",
|
|
102
97
|
"x-project-id": this.projectId
|
|
103
98
|
},
|
|
104
|
-
credentials: "include",
|
|
105
99
|
body: JSON.stringify(beginParams)
|
|
106
100
|
});
|
|
107
101
|
if (!beginResponse.ok) {
|
|
@@ -112,14 +106,16 @@ var PlainKeyClient = class {
|
|
|
112
106
|
if (!beginResponseData.options) throw new Error("No options found in login begin response");
|
|
113
107
|
const authenticationResponse = await startAuthentication({ optionsJSON: beginResponseData.options });
|
|
114
108
|
if (!authenticationResponse) throw new Error("No authentication response from browser");
|
|
115
|
-
const completeParams = {
|
|
109
|
+
const completeParams = {
|
|
110
|
+
loginSessionId: beginResponseData.loginSession.id,
|
|
111
|
+
authenticationResponse
|
|
112
|
+
};
|
|
116
113
|
const verificationResponse = await fetch(`${this.baseUrl}/login/complete`, {
|
|
117
114
|
method: "POST",
|
|
118
115
|
headers: {
|
|
119
116
|
"Content-Type": "application/json",
|
|
120
117
|
"x-project-id": this.projectId
|
|
121
118
|
},
|
|
122
|
-
credentials: "include",
|
|
123
119
|
body: JSON.stringify(completeParams)
|
|
124
120
|
});
|
|
125
121
|
if (!verificationResponse.ok) {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["errorData: ErrorResponse","credential: RegistrationResponseJSON","completeParams: RegistrationCompleteRequest","response: RegistrationCompleteResponse","completeParams: UserCredentialCompleteRequest","response: UserCredentialCompleteResponse","beginResponseData: LoginBeginResponse","authenticationResponse: AuthenticationResponseJSON","completeParams: LoginCompleteRequest","verificationResponseData: LoginCompleteResponse"],"sources":["../src/plainkey-client.ts"],"sourcesContent":["import { startAuthentication, startRegistration } from \"@simplewebauthn/browser\"\nimport { RegistrationResponseJSON, AuthenticationResponseJSON } from \"@simplewebauthn/browser\"\n\nimport type {\n RegistrationBeginRequest,\n RegistrationCompleteRequest,\n UserCredentialBeginRequest,\n UserCredentialCompleteRequest,\n LoginBeginRequest,\n LoginCompleteRequest\n} from \"@plainkey/types\"\n\nimport type {\n RegistrationBeginResponse,\n RegistrationCompleteResponse,\n UserCredentialBeginResponse,\n UserCredentialCompleteResponse,\n LoginBeginResponse,\n LoginCompleteResponse,\n ErrorResponse\n} from \"@plainkey/types\"\n\nexport type PlainKeyClientParams = {\n projectId: string\n baseUrl?: string\n}\n\n// TODO: Account for errors like this: \"Unexpected token 'R', \"Response v\"... is not valid JSON\"\nexport class PlainKeyClient {\n private readonly projectId: string\n private readonly baseUrl: string\n\n constructor(clientParams: PlainKeyClientParams) {\n const { projectId, baseUrl = \"https://api.plainkey.io/api\" } = clientParams\n\n this.projectId = projectId\n this.baseUrl = baseUrl.replace(/\\/$/, \"\") // Remove trailing slash\n }\n\n /**\n * Registration of a new user with passkey.\n * Creates a new user and adds a credential to it.\n */\n async Registration(beginParams: RegistrationBeginRequest): Promise<RegistrationCompleteResponse> {\n // Step 1: Get registration options from server\n const headers = new Headers({\n \"Content-Type\": \"application/json\",\n \"x-project-id\": this.projectId\n })\n\n const beginResponse = await fetch(`${this.baseUrl}/user/register/begin`, {\n method: \"POST\",\n headers,\n credentials: \"include\",\n body: JSON.stringify(beginParams)\n })\n\n if (!beginResponse.ok) {\n const errorData: ErrorResponse = await beginResponse.json()\n throw new Error(errorData.error)\n }\n\n const { options, user } = (await beginResponse.json()) as RegistrationBeginResponse\n\n // Step 2: Create credential using browser's WebAuthn API\n const credential: RegistrationResponseJSON = await startRegistration({\n optionsJSON: options\n })\n\n // Step 3: Send credential to server for verification\n const completeParams: RegistrationCompleteRequest = {\n userIdentifier: { userId: user.id },\n credential\n }\n\n const completeResponse = await fetch(`${this.baseUrl}/user/register/complete`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-project-id\": this.projectId\n },\n credentials: \"include\",\n body: JSON.stringify(completeParams)\n })\n\n if (!completeResponse.ok) {\n const errorData: ErrorResponse = await completeResponse.json()\n throw new Error(errorData.error)\n }\n\n // Intentionally not throwing errors on verification failure - UI should handle this.\n const response: RegistrationCompleteResponse = await completeResponse.json()\n if (!response) throw new Error(\"No registration response from server\")\n\n return response\n }\n\n /**\n * Add credential to existing user.\n * Requires valid user authentication token (log user in first which will set a user token cookie, then call this).\n */\n async AddCredential(\n beginParams: UserCredentialBeginRequest\n ): Promise<UserCredentialCompleteResponse> {\n // Step 1: Get credential registration options from server\n const headers = new Headers({\n \"Content-Type\": \"application/json\",\n \"x-project-id\": this.projectId\n })\n\n const beginResponse = await fetch(`${this.baseUrl}/user/credential/begin`, {\n method: \"POST\",\n headers,\n credentials: \"include\",\n body: JSON.stringify(beginParams)\n })\n\n if (!beginResponse.ok) {\n const errorData: ErrorResponse = await beginResponse.json()\n throw new Error(errorData.error)\n }\n\n const { options, user } = (await beginResponse.json()) as UserCredentialBeginResponse\n\n // Step 2: Create credential using browser's WebAuthn API\n const credential: RegistrationResponseJSON = await startRegistration({\n optionsJSON: options\n })\n\n // Step 3: Send credential to server for verification\n const completeParams: UserCredentialCompleteRequest = {\n userIdentifier: { userId: user.id },\n credential\n }\n\n const completeResponse = await fetch(`${this.baseUrl}/user/credential/complete`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-project-id\": this.projectId\n },\n credentials: \"include\",\n body: JSON.stringify(completeParams)\n })\n\n if (!completeResponse.ok) {\n const errorData: ErrorResponse = await completeResponse.json()\n throw new Error(errorData.error)\n }\n\n // Intentionally not throwing errors on verification failure - UI should handle this.\n const response: UserCredentialCompleteResponse = await completeResponse.json()\n if (!response) throw new Error(\"No credential registration response from server\")\n\n return response\n }\n\n /**\n * Performs a login ceremony.\n */\n async Login(beginParams: LoginBeginRequest): Promise<LoginCompleteResponse> {\n // Step 1: Get authentication options from server\n const beginResponse = await fetch(`${this.baseUrl}/login/begin`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-project-id\": this.projectId\n },\n credentials: \"include\",\n body: JSON.stringify(beginParams)\n })\n\n if (!beginResponse.ok) {\n const errorData: ErrorResponse = await beginResponse.json()\n throw new Error(errorData.error)\n }\n\n const beginResponseData: LoginBeginResponse = await beginResponse.json()\n if (!beginResponseData.options) {\n throw new Error(\"No options found in login begin response\")\n }\n\n // Step 2: Pass options to the authenticator and wait for response\n const authenticationResponse: AuthenticationResponseJSON = await startAuthentication({\n optionsJSON: beginResponseData.options\n })\n\n if (!authenticationResponse) {\n throw new Error(\"No authentication response from browser\")\n }\n\n // Step 3: POST the response to the server\n const completeParams: LoginCompleteRequest = { authenticationResponse }\n\n const verificationResponse = await fetch(`${this.baseUrl}/login/complete`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-project-id\": this.projectId\n },\n credentials: \"include\",\n body: JSON.stringify(completeParams)\n })\n\n if (!verificationResponse.ok) {\n const errorData: ErrorResponse = await verificationResponse.json()\n throw new Error(errorData.error)\n }\n\n // Intentionally not throwing errors on verification failure - UI should handle this.\n const verificationResponseData: LoginCompleteResponse = await verificationResponse.json()\n if (!verificationResponseData) throw new Error(\"No login verification response from server\")\n\n return verificationResponseData\n }\n}\n"],"mappings":";;;AA4BA,IAAa,iBAAb,MAA4B;CAI1B,YAAY,cAAoC;EAC9C,MAAM,EAAE,WAAW,UAAU,kCAAkC;AAE/D,OAAK,YAAY;AACjB,OAAK,UAAU,QAAQ,QAAQ,OAAO,GAAG;;;;;;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,kBAAkB;GACzE,QAAQ;GACR,SAAS;IACP,gBAAgB;IAChB,gBAAgB,KAAK;IACtB;GACD,aAAa;GACb,MAAM,KAAK,UAAU,eAAe;GACrC,CAAC;AAEF,MAAI,CAAC,qBAAqB,IAAI;GAC5B,MAAMR,YAA2B,MAAM,qBAAqB,MAAM;AAClE,SAAM,IAAI,MAAM,UAAU,MAAM;;EAIlC,MAAMS,2BAAkD,MAAM,qBAAqB,MAAM;AACzF,MAAI,CAAC,yBAA0B,OAAM,IAAI,MAAM,6CAA6C;AAE5F,SAAO"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["errorData: ErrorResponse","credential: RegistrationResponseJSON","completeParams: RegistrationCompleteRequest","response: RegistrationCompleteResponse","completeParams: UserCredentialCompleteRequest","response: UserCredentialCompleteResponse","beginResponseData: LoginBeginResponse","authenticationResponse: AuthenticationResponseJSON","completeParams: LoginCompleteRequest","verificationResponseData: LoginCompleteResponse"],"sources":["../src/plainkey-client.ts"],"sourcesContent":["import { startAuthentication, startRegistration } from \"@simplewebauthn/browser\"\nimport { RegistrationResponseJSON, AuthenticationResponseJSON } from \"@simplewebauthn/browser\"\n\nimport type {\n RegistrationBeginRequest,\n RegistrationCompleteRequest,\n UserCredentialBeginRequest,\n UserCredentialCompleteRequest,\n LoginBeginRequest,\n LoginCompleteRequest\n} from \"@plainkey/types\"\n\nimport type {\n RegistrationBeginResponse,\n RegistrationCompleteResponse,\n UserCredentialBeginResponse,\n UserCredentialCompleteResponse,\n LoginBeginResponse,\n LoginCompleteResponse,\n ErrorResponse\n} from \"@plainkey/types\"\n\nexport type PlainKeyClientParams = {\n projectId: string\n baseUrl?: string\n}\n\n// TODO: Account for errors like this: \"Unexpected token 'R', \"Response v\"... is not valid JSON\"\nexport class PlainKeyClient {\n private readonly projectId: string\n private readonly baseUrl: string\n\n constructor(clientParams: PlainKeyClientParams) {\n const { projectId, baseUrl = \"https://api.plainkey.io/api\" } = clientParams\n\n this.projectId = projectId\n this.baseUrl = baseUrl.replace(/\\/$/, \"\") // Remove trailing slash\n }\n\n /**\n * Registration of a new user with passkey.\n * Creates a new user and adds a credential to it.\n */\n async Registration(beginParams: RegistrationBeginRequest): Promise<RegistrationCompleteResponse> {\n // Step 1: Get registration options from server\n const beginResponse = await fetch(`${this.baseUrl}/user/register/begin`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-project-id\": this.projectId\n },\n body: JSON.stringify(beginParams)\n })\n\n if (!beginResponse.ok) {\n const errorData: ErrorResponse = await beginResponse.json()\n throw new Error(errorData.error)\n }\n\n const { options, user } = (await beginResponse.json()) as RegistrationBeginResponse\n\n // Step 2: Create credential using browser's WebAuthn API\n const credential: RegistrationResponseJSON = await startRegistration({\n optionsJSON: options\n })\n\n // Step 3: Send credential to server for verification\n const completeParams: RegistrationCompleteRequest = {\n userIdentifier: { userId: user.id },\n credential\n }\n\n const completeResponse = await fetch(`${this.baseUrl}/user/register/complete`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-project-id\": this.projectId\n },\n body: JSON.stringify(completeParams)\n })\n\n if (!completeResponse.ok) {\n const errorData: ErrorResponse = await completeResponse.json()\n throw new Error(errorData.error)\n }\n\n // Intentionally not throwing errors on verification failure - UI should handle this.\n const response: RegistrationCompleteResponse = await completeResponse.json()\n if (!response) throw new Error(\"No registration response from server\")\n\n return response\n }\n\n /**\n * Add credential to existing user.\n * Requires a valid user authentication token passed in beginParams, which will be sent in the request body.\n * However, do not store the token in local storage, database, etc. Always keep it in memory.\n */\n async AddCredential(\n beginParams: UserCredentialBeginRequest\n ): Promise<UserCredentialCompleteResponse> {\n // Step 1: Get credential registration options from server\n\n const beginResponse = await fetch(`${this.baseUrl}/user/credential/begin`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-project-id\": this.projectId\n },\n body: JSON.stringify(beginParams)\n })\n\n if (!beginResponse.ok) {\n const errorData: ErrorResponse = await beginResponse.json()\n throw new Error(errorData.error)\n }\n\n const { options, user } = (await beginResponse.json()) as UserCredentialBeginResponse\n\n // Step 2: Create credential using browser's WebAuthn API\n const credential: RegistrationResponseJSON = await startRegistration({\n optionsJSON: options\n })\n\n // Step 3: Send credential to server for verification\n const completeParams: UserCredentialCompleteRequest = {\n userIdentifier: { userId: user.id },\n credential\n }\n\n const completeResponse = await fetch(`${this.baseUrl}/user/credential/complete`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-project-id\": this.projectId\n },\n body: JSON.stringify(completeParams)\n })\n\n if (!completeResponse.ok) {\n const errorData: ErrorResponse = await completeResponse.json()\n throw new Error(errorData.error)\n }\n\n // Intentionally not throwing errors on verification failure - UI should handle this.\n const response: UserCredentialCompleteResponse = await completeResponse.json()\n if (!response) throw new Error(\"No credential registration response from server\")\n\n return response\n }\n\n /**\n * Performs a login ceremony.\n */\n async Login(beginParams: LoginBeginRequest): Promise<LoginCompleteResponse> {\n // Step 1: Get authentication options from server\n const beginResponse = await fetch(`${this.baseUrl}/login/begin`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-project-id\": this.projectId\n },\n body: JSON.stringify(beginParams)\n })\n\n if (!beginResponse.ok) {\n const errorData: ErrorResponse = await beginResponse.json()\n throw new Error(errorData.error)\n }\n\n const beginResponseData: LoginBeginResponse = await beginResponse.json()\n if (!beginResponseData.options) {\n throw new Error(\"No options found in login begin response\")\n }\n\n // Step 2: Pass options to the authenticator and wait for response\n const authenticationResponse: AuthenticationResponseJSON = await startAuthentication({\n optionsJSON: beginResponseData.options\n })\n\n if (!authenticationResponse) {\n throw new Error(\"No authentication response from browser\")\n }\n\n // Step 3: POST the response to the server\n // This uses the login session ID from the begin response - always in JS memory.\n // Do not store it in local storage, database, etc.\n const completeParams: LoginCompleteRequest = {\n loginSessionId: beginResponseData.loginSession.id,\n authenticationResponse\n }\n\n const verificationResponse = await fetch(`${this.baseUrl}/login/complete`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-project-id\": this.projectId\n },\n body: JSON.stringify(completeParams)\n })\n\n if (!verificationResponse.ok) {\n const errorData: ErrorResponse = await verificationResponse.json()\n throw new Error(errorData.error)\n }\n\n // Intentionally not throwing errors on verification failure - UI should handle this.\n const verificationResponseData: LoginCompleteResponse = await verificationResponse.json()\n if (!verificationResponseData) throw new Error(\"No login verification response from server\")\n\n return verificationResponseData\n }\n}\n"],"mappings":";;;AA4BA,IAAa,iBAAb,MAA4B;CAI1B,YAAY,cAAoC;EAC9C,MAAM,EAAE,WAAW,UAAU,kCAAkC;AAE/D,OAAK,YAAY;AACjB,OAAK,UAAU,QAAQ,QAAQ,OAAO,GAAG;;;;;;CAO3C,MAAM,aAAa,aAA8E;EAE/F,MAAM,gBAAgB,MAAM,MAAM,GAAG,KAAK,QAAQ,uBAAuB;GACvE,QAAQ;GACR,SAAS;IACP,gBAAgB;IAChB,gBAAgB,KAAK;IACtB;GACD,MAAM,KAAK,UAAU,YAAY;GAClC,CAAC;AAEF,MAAI,CAAC,cAAc,IAAI;GACrB,MAAMA,YAA2B,MAAM,cAAc,MAAM;AAC3D,SAAM,IAAI,MAAM,UAAU,MAAM;;EAGlC,MAAM,EAAE,SAAS,SAAU,MAAM,cAAc,MAAM;EAGrD,MAAMC,aAAuC,MAAM,kBAAkB,EACnE,aAAa,SACd,CAAC;EAGF,MAAMC,iBAA8C;GAClD,gBAAgB,EAAE,QAAQ,KAAK,IAAI;GACnC;GACD;EAED,MAAM,mBAAmB,MAAM,MAAM,GAAG,KAAK,QAAQ,0BAA0B;GAC7E,QAAQ;GACR,SAAS;IACP,gBAAgB;IAChB,gBAAgB,KAAK;IACtB;GACD,MAAM,KAAK,UAAU,eAAe;GACrC,CAAC;AAEF,MAAI,CAAC,iBAAiB,IAAI;GACxB,MAAMF,YAA2B,MAAM,iBAAiB,MAAM;AAC9D,SAAM,IAAI,MAAM,UAAU,MAAM;;EAIlC,MAAMG,WAAyC,MAAM,iBAAiB,MA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