@rockerone/xprnkit 0.4.1 → 0.4.2

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.
@@ -17,7 +17,9 @@ export type XPRNKitIdentityProof = {
17
17
  export type XPRNKitIdentityProofConfig = {
18
18
  required: boolean;
19
19
  createUrl: string;
20
+ createIdentityResponseTransformer?: (response: any) => any;
20
21
  validationUrl?: string;
22
+ validationIdentityResponseTransformer?: (response: any) => any;
21
23
  validationBuffer?: number;
22
24
  headers?: Record<string, string>;
23
25
  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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rockerone/xprnkit",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "source": "src/index.ts",
5
5
  "main": "build/index.js",
6
6
  "type": "module",