@rockerone/xprnkit 0.4.1 → 0.4.3
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/build/interfaces/identity-proof.d.ts +5 -0
- package/build/providers/xprnkit-provider.js +2 -2
- package/build/services/identity-proof/authenticate-identity-proof.d.ts +1 -1
- package/build/services/identity-proof/authenticate-identity-proof.js +4 -1
- package/build/services/identity-proof/verify-identity-proof.d.ts +1 -1
- package/build/services/identity-proof/verify-identity-proof.js +4 -1
- package/package.json +1 -1
|
@@ -13,11 +13,16 @@ export type XPRNKitIdentityProof = {
|
|
|
13
13
|
permission: string;
|
|
14
14
|
};
|
|
15
15
|
token: string;
|
|
16
|
+
metadata: {
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
};
|
|
16
19
|
};
|
|
17
20
|
export type XPRNKitIdentityProofConfig = {
|
|
18
21
|
required: boolean;
|
|
19
22
|
createUrl: string;
|
|
23
|
+
createIdentityResponseTransformer?: (response: any) => any;
|
|
20
24
|
validationUrl?: string;
|
|
25
|
+
validationIdentityResponseTransformer?: (response: any) => any;
|
|
21
26
|
validationBuffer?: number;
|
|
22
27
|
headers?: Record<string, string>;
|
|
23
28
|
timeout?: number;
|
|
@@ -92,7 +92,7 @@ export const XPRNProvider = ({ children, config, }) => {
|
|
|
92
92
|
return;
|
|
93
93
|
}
|
|
94
94
|
try {
|
|
95
|
-
const identityProof = await authenticateIdentityProof(identityProofPayload, config.identityProof);
|
|
95
|
+
const identityProof = await authenticateIdentityProof(identityProofPayload, config.identityProof, new AbortController().signal, config.identityProof.createIdentityResponseTransformer);
|
|
96
96
|
const identityStorageKey = getIdentityProofStorageKey(session.auth.actor.toString(), session.auth.permission.toString(), session.chainId.toString());
|
|
97
97
|
console.log('writing identity proof to storage', identityProof);
|
|
98
98
|
identityProofStorage.write(identityStorageKey, JSON.stringify(identityProof));
|
|
@@ -121,7 +121,7 @@ export const XPRNProvider = ({ children, config, }) => {
|
|
|
121
121
|
const identityProof = storedProof ? JSON.parse(storedProof) : null;
|
|
122
122
|
console.log('identityProof', identityProof);
|
|
123
123
|
if (identityProof) {
|
|
124
|
-
const validationResult = await verfiyIdentityProof(identityProof, config.identityProof);
|
|
124
|
+
const validationResult = await verfiyIdentityProof(identityProof, config.identityProof, new AbortController().signal, config.identityProof.validationIdentityResponseTransformer);
|
|
125
125
|
console.log('validationResult', validationResult);
|
|
126
126
|
if (validationResult) {
|
|
127
127
|
resolve(identityProof);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { XPRNKitIdentityProof, XPRNKitIdentityProofConfig, XPRNKitIdentityProofPayload } from "interfaces/identity-proof";
|
|
2
|
-
export declare function authenticateIdentityProof(payload: XPRNKitIdentityProofPayload, config: XPRNKitIdentityProofConfig, signal?: AbortSignal): Promise<XPRNKitIdentityProof>;
|
|
2
|
+
export declare function authenticateIdentityProof(payload: XPRNKitIdentityProofPayload, config: XPRNKitIdentityProofConfig, signal?: AbortSignal, transformer?: (response: any) => any): Promise<XPRNKitIdentityProof>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export async function authenticateIdentityProof(payload, config, signal) {
|
|
1
|
+
export async function authenticateIdentityProof(payload, config, signal, transformer) {
|
|
2
2
|
// Check for abort before starting
|
|
3
3
|
if (signal?.aborted) {
|
|
4
4
|
throw new DOMException("Aborted", "AbortError");
|
|
@@ -38,5 +38,8 @@ export async function authenticateIdentityProof(payload, config, signal) {
|
|
|
38
38
|
}
|
|
39
39
|
// Parse and return response
|
|
40
40
|
const result = await response.json();
|
|
41
|
+
if (transformer) {
|
|
42
|
+
return transformer(result);
|
|
43
|
+
}
|
|
41
44
|
return result;
|
|
42
45
|
}
|
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* without requiring a new wallet signature.
|
|
6
6
|
*/
|
|
7
7
|
import { XPRNKitIdentityProof, XPRNKitIdentityProofConfig } from "interfaces/identity-proof";
|
|
8
|
-
export declare function verfiyIdentityProof(proof: XPRNKitIdentityProof, config: XPRNKitIdentityProofConfig, signal?: AbortSignal): Promise<XPRNKitIdentityProof>;
|
|
8
|
+
export declare function verfiyIdentityProof(proof: XPRNKitIdentityProof, config: XPRNKitIdentityProofConfig, signal?: AbortSignal, transformer?: (response: any) => any): Promise<XPRNKitIdentityProof>;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This is used to extend/refresh a token that is approaching expiration
|
|
5
5
|
* without requiring a new wallet signature.
|
|
6
6
|
*/
|
|
7
|
-
export async function verfiyIdentityProof(proof, config, signal) {
|
|
7
|
+
export async function verfiyIdentityProof(proof, config, signal, transformer) {
|
|
8
8
|
return new Promise(async (resolve, reject) => {
|
|
9
9
|
const { validationUrl, headers, timeout } = config;
|
|
10
10
|
// Check for abort before starting
|
|
@@ -41,6 +41,9 @@ export async function verfiyIdentityProof(proof, config, signal) {
|
|
|
41
41
|
// Handle response
|
|
42
42
|
if (response.ok) {
|
|
43
43
|
const data = await response.json();
|
|
44
|
+
if (transformer) {
|
|
45
|
+
return transformer(data);
|
|
46
|
+
}
|
|
44
47
|
resolve(proof);
|
|
45
48
|
}
|
|
46
49
|
// Non-OK response means invalid
|