noah-avalanche-sdk 0.1.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.
- package/README.md +892 -0
- package/dist/core/APIClient.d.ts +71 -0
- package/dist/core/APIClient.d.ts.map +1 -0
- package/dist/core/APIClient.js +92 -0
- package/dist/core/APIClient.js.map +1 -0
- package/dist/core/ContractClient.d.ts +38 -0
- package/dist/core/ContractClient.d.ts.map +1 -0
- package/dist/core/ContractClient.js +209 -0
- package/dist/core/ContractClient.js.map +1 -0
- package/dist/core/NoahSDK.d.ts +43 -0
- package/dist/core/NoahSDK.d.ts.map +1 -0
- package/dist/core/NoahSDK.js +93 -0
- package/dist/core/NoahSDK.js.map +1 -0
- package/dist/core/WalletAdapter.d.ts +188 -0
- package/dist/core/WalletAdapter.d.ts.map +1 -0
- package/dist/core/WalletAdapter.js +425 -0
- package/dist/core/WalletAdapter.js.map +1 -0
- package/dist/hooks/index.d.ts +18 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +15 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useCredentials.d.ts +136 -0
- package/dist/hooks/useCredentials.d.ts.map +1 -0
- package/dist/hooks/useCredentials.js +217 -0
- package/dist/hooks/useCredentials.js.map +1 -0
- package/dist/hooks/useProtocol.d.ts +117 -0
- package/dist/hooks/useProtocol.d.ts.map +1 -0
- package/dist/hooks/useProtocol.js +165 -0
- package/dist/hooks/useProtocol.js.map +1 -0
- package/dist/hooks/useUser.d.ts +159 -0
- package/dist/hooks/useUser.d.ts.map +1 -0
- package/dist/hooks/useUser.js +188 -0
- package/dist/hooks/useUser.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/issuer/IssuerClient.d.ts +98 -0
- package/dist/issuer/IssuerClient.d.ts.map +1 -0
- package/dist/issuer/IssuerClient.js +159 -0
- package/dist/issuer/IssuerClient.js.map +1 -0
- package/dist/protocol/ProtocolClient.d.ts +124 -0
- package/dist/protocol/ProtocolClient.d.ts.map +1 -0
- package/dist/protocol/ProtocolClient.js +265 -0
- package/dist/protocol/ProtocolClient.js.map +1 -0
- package/dist/protocol/RequirementsManager.d.ts +9 -0
- package/dist/protocol/RequirementsManager.d.ts.map +1 -0
- package/dist/protocol/RequirementsManager.js +9 -0
- package/dist/protocol/RequirementsManager.js.map +1 -0
- package/dist/user/ProofGenerator.d.ts +49 -0
- package/dist/user/ProofGenerator.d.ts.map +1 -0
- package/dist/user/ProofGenerator.js +80 -0
- package/dist/user/ProofGenerator.js.map +1 -0
- package/dist/user/UserClient.d.ts +191 -0
- package/dist/user/UserClient.d.ts.map +1 -0
- package/dist/user/UserClient.js +338 -0
- package/dist/user/UserClient.js.map +1 -0
- package/dist/utils/credentials.d.ts +47 -0
- package/dist/utils/credentials.d.ts.map +1 -0
- package/dist/utils/credentials.js +99 -0
- package/dist/utils/credentials.js.map +1 -0
- package/dist/utils/identity.d.ts +22 -0
- package/dist/utils/identity.d.ts.map +1 -0
- package/dist/utils/identity.js +35 -0
- package/dist/utils/identity.js.map +1 -0
- package/dist/utils/jurisdiction.d.ts +21 -0
- package/dist/utils/jurisdiction.d.ts.map +1 -0
- package/dist/utils/jurisdiction.js +64 -0
- package/dist/utils/jurisdiction.js.map +1 -0
- package/dist/utils/mrz.d.ts +16 -0
- package/dist/utils/mrz.d.ts.map +1 -0
- package/dist/utils/mrz.js +91 -0
- package/dist/utils/mrz.js.map +1 -0
- package/dist/utils/ocr.d.ts +31 -0
- package/dist/utils/ocr.d.ts.map +1 -0
- package/dist/utils/ocr.js +69 -0
- package/dist/utils/ocr.js.map +1 -0
- package/dist/utils/types.d.ts +122 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.js +2 -0
- package/dist/utils/types.js.map +1 -0
- package/package.json +53 -0
- package/src/core/APIClient.ts +165 -0
- package/src/core/ContractClient.ts +266 -0
- package/src/core/NoahSDK.ts +123 -0
- package/src/core/WalletAdapter.ts +546 -0
- package/src/hooks/index.ts +31 -0
- package/src/hooks/types.d.ts +18 -0
- package/src/hooks/useCredentials.ts +359 -0
- package/src/hooks/useProtocol.ts +284 -0
- package/src/hooks/useUser.ts +331 -0
- package/src/index.ts +80 -0
- package/src/issuer/IssuerClient.ts +209 -0
- package/src/protocol/ProtocolClient.ts +330 -0
- package/src/protocol/RequirementsManager.ts +16 -0
- package/src/user/ProofGenerator.ts +113 -0
- package/src/user/UserClient.ts +440 -0
- package/src/utils/credentials.ts +122 -0
- package/src/utils/identity.ts +46 -0
- package/src/utils/jurisdiction.ts +83 -0
- package/src/utils/mrz.ts +113 -0
- package/src/utils/ocr.ts +84 -0
- package/src/utils/types.ts +144 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { Signer } from 'ethers';
|
|
2
|
+
import { UserClient, type Credential as UserCredential } from '../user/UserClient';
|
|
3
|
+
import type { Requirements, TransactionResult, ZKProof } from '../utils/types';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for useUser hook
|
|
6
|
+
*/
|
|
7
|
+
export interface UseUserOptions {
|
|
8
|
+
/** User's wallet address */
|
|
9
|
+
userAddress?: string;
|
|
10
|
+
/** Protocol address to check requirements/access for */
|
|
11
|
+
protocolAddress?: string;
|
|
12
|
+
/** Credential hash to check validity for */
|
|
13
|
+
credentialHash?: string;
|
|
14
|
+
/** Whether to enable automatic refetching */
|
|
15
|
+
enabled?: boolean;
|
|
16
|
+
/** React Query configuration options */
|
|
17
|
+
queryOptions?: {
|
|
18
|
+
refetchInterval?: number;
|
|
19
|
+
staleTime?: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Credential structure (re-exported from UserClient for convenience)
|
|
24
|
+
*/
|
|
25
|
+
export type Credential = UserCredential;
|
|
26
|
+
/**
|
|
27
|
+
* Return type for useUser hook
|
|
28
|
+
*/
|
|
29
|
+
export interface UseUserReturn {
|
|
30
|
+
user: UserClient | null;
|
|
31
|
+
protocolRequirements: Requirements | undefined;
|
|
32
|
+
isLoadingRequirements: boolean;
|
|
33
|
+
requirementsError: Error | null;
|
|
34
|
+
refetchRequirements: () => void;
|
|
35
|
+
isCredentialValid: boolean | undefined;
|
|
36
|
+
isLoadingCredential: boolean;
|
|
37
|
+
credentialError: Error | null;
|
|
38
|
+
refetchCredential: () => void;
|
|
39
|
+
checkCredentialValidity: {
|
|
40
|
+
mutate: (credentialHash: string) => void;
|
|
41
|
+
mutateAsync: (credentialHash: string) => Promise<boolean>;
|
|
42
|
+
isLoading: boolean;
|
|
43
|
+
error: Error | null;
|
|
44
|
+
reset: () => void;
|
|
45
|
+
};
|
|
46
|
+
generateProof: {
|
|
47
|
+
mutate: (params: {
|
|
48
|
+
credential: Credential;
|
|
49
|
+
requirements: Requirements & {
|
|
50
|
+
protocolAddress: string;
|
|
51
|
+
};
|
|
52
|
+
}) => void;
|
|
53
|
+
mutateAsync: (params: {
|
|
54
|
+
credential: Credential;
|
|
55
|
+
requirements: Requirements & {
|
|
56
|
+
protocolAddress: string;
|
|
57
|
+
};
|
|
58
|
+
}) => Promise<{
|
|
59
|
+
proof: ZKProof;
|
|
60
|
+
publicSignals: string[];
|
|
61
|
+
nullifier: string;
|
|
62
|
+
packedFlags: number;
|
|
63
|
+
credentialHash: string;
|
|
64
|
+
success: boolean;
|
|
65
|
+
}>;
|
|
66
|
+
isLoading: boolean;
|
|
67
|
+
error: Error | null;
|
|
68
|
+
reset: () => void;
|
|
69
|
+
};
|
|
70
|
+
verifyAndGrantAccess: {
|
|
71
|
+
mutate: (params: {
|
|
72
|
+
proof: ZKProof;
|
|
73
|
+
publicSignals: string[];
|
|
74
|
+
nullifier: string;
|
|
75
|
+
packedFlags: number;
|
|
76
|
+
credentialHash: string;
|
|
77
|
+
protocolAddress?: string;
|
|
78
|
+
userAddress?: string;
|
|
79
|
+
}) => void;
|
|
80
|
+
mutateAsync: (params: {
|
|
81
|
+
proof: ZKProof;
|
|
82
|
+
publicSignals: string[];
|
|
83
|
+
nullifier: string;
|
|
84
|
+
packedFlags: number;
|
|
85
|
+
credentialHash: string;
|
|
86
|
+
protocolAddress?: string;
|
|
87
|
+
userAddress?: string;
|
|
88
|
+
}) => Promise<TransactionResult>;
|
|
89
|
+
isLoading: boolean;
|
|
90
|
+
error: Error | null;
|
|
91
|
+
reset: () => void;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* React hook for user operations
|
|
96
|
+
*
|
|
97
|
+
* Provides easy access to user-related functionality including:
|
|
98
|
+
* - Getting protocol requirements
|
|
99
|
+
* - Checking credential validity
|
|
100
|
+
* - Generating ZK proofs
|
|
101
|
+
* - Verifying proofs and granting access to protocols
|
|
102
|
+
*
|
|
103
|
+
* @param signer - Ethers signer instance (from wallet)
|
|
104
|
+
* @param options - Configuration options
|
|
105
|
+
* @returns Hook return object with user operations
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```tsx
|
|
109
|
+
* import { useUser } from '@noah-protocol/sdk/hooks';
|
|
110
|
+
* import { useSigner, useAccount } from 'wagmi';
|
|
111
|
+
*
|
|
112
|
+
* function UserDashboard() {
|
|
113
|
+
* const { data: signer } = useSigner();
|
|
114
|
+
* const { address } = useAccount();
|
|
115
|
+
* const {
|
|
116
|
+
* protocolRequirements,
|
|
117
|
+
* generateProof,
|
|
118
|
+
* verifyAndGrantAccess,
|
|
119
|
+
* hasAccess
|
|
120
|
+
* } = useUser(signer, {
|
|
121
|
+
* userAddress: address,
|
|
122
|
+
* protocolAddress: '0x...',
|
|
123
|
+
* apiBaseUrl: 'https://api.noah.xyz'
|
|
124
|
+
* });
|
|
125
|
+
*
|
|
126
|
+
* const handleGenerateProof = async () => {
|
|
127
|
+
* const result = await generateProof.mutateAsync({
|
|
128
|
+
* credential: {
|
|
129
|
+
* actualAge: 25,
|
|
130
|
+
* actualJurisdiction: 'US',
|
|
131
|
+
* actualAccredited: true,
|
|
132
|
+
* credentialHash: '0x...'
|
|
133
|
+
* },
|
|
134
|
+
* requirements: protocolRequirements!
|
|
135
|
+
* });
|
|
136
|
+
*
|
|
137
|
+
* await verifyAndGrantAccess.mutateAsync({
|
|
138
|
+
* ...result,
|
|
139
|
+
* credentialHash: '0x...',
|
|
140
|
+
* protocolAddress: '0x...'
|
|
141
|
+
* });
|
|
142
|
+
* };
|
|
143
|
+
*
|
|
144
|
+
* return (
|
|
145
|
+
* <div>
|
|
146
|
+
* {hasAccess ? (
|
|
147
|
+
* <p>You have access!</p>
|
|
148
|
+
* ) : (
|
|
149
|
+
* <button onClick={handleGenerateProof}>
|
|
150
|
+
* Request Access
|
|
151
|
+
* </button>
|
|
152
|
+
* )}
|
|
153
|
+
* </div>
|
|
154
|
+
* );
|
|
155
|
+
* }
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export declare function useUser(signer: Signer | null | undefined, options?: UseUserOptions): UseUserReturn;
|
|
159
|
+
//# sourceMappingURL=useUser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUser.d.ts","sourceRoot":"","sources":["../../src/hooks/useUser.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,KAAK,UAAU,IAAI,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACnF,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE/E;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,4BAA4B;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wDAAwD;IACxD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4CAA4C;IAC5C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,6CAA6C;IAC7C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,wCAAwC;I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@ -0,0 +1,188 @@
|
|
|
1
|
+
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { UserClient } from '../user/UserClient';
|
|
4
|
+
/**
|
|
5
|
+
* React hook for user operations
|
|
6
|
+
*
|
|
7
|
+
* Provides easy access to user-related functionality including:
|
|
8
|
+
* - Getting protocol requirements
|
|
9
|
+
* - Checking credential validity
|
|
10
|
+
* - Generating ZK proofs
|
|
11
|
+
* - Verifying proofs and granting access to protocols
|
|
12
|
+
*
|
|
13
|
+
* @param signer - Ethers signer instance (from wallet)
|
|
14
|
+
* @param options - Configuration options
|
|
15
|
+
* @returns Hook return object with user operations
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* import { useUser } from '@noah-protocol/sdk/hooks';
|
|
20
|
+
* import { useSigner, useAccount } from 'wagmi';
|
|
21
|
+
*
|
|
22
|
+
* function UserDashboard() {
|
|
23
|
+
* const { data: signer } = useSigner();
|
|
24
|
+
* const { address } = useAccount();
|
|
25
|
+
* const {
|
|
26
|
+
* protocolRequirements,
|
|
27
|
+
* generateProof,
|
|
28
|
+
* verifyAndGrantAccess,
|
|
29
|
+
* hasAccess
|
|
30
|
+
* } = useUser(signer, {
|
|
31
|
+
* userAddress: address,
|
|
32
|
+
* protocolAddress: '0x...',
|
|
33
|
+
* apiBaseUrl: 'https://api.noah.xyz'
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* const handleGenerateProof = async () => {
|
|
37
|
+
* const result = await generateProof.mutateAsync({
|
|
38
|
+
* credential: {
|
|
39
|
+
* actualAge: 25,
|
|
40
|
+
* actualJurisdiction: 'US',
|
|
41
|
+
* actualAccredited: true,
|
|
42
|
+
* credentialHash: '0x...'
|
|
43
|
+
* },
|
|
44
|
+
* requirements: protocolRequirements!
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* await verifyAndGrantAccess.mutateAsync({
|
|
48
|
+
* ...result,
|
|
49
|
+
* credentialHash: '0x...',
|
|
50
|
+
* protocolAddress: '0x...'
|
|
51
|
+
* });
|
|
52
|
+
* };
|
|
53
|
+
*
|
|
54
|
+
* return (
|
|
55
|
+
* <div>
|
|
56
|
+
* {hasAccess ? (
|
|
57
|
+
* <p>You have access!</p>
|
|
58
|
+
* ) : (
|
|
59
|
+
* <button onClick={handleGenerateProof}>
|
|
60
|
+
* Request Access
|
|
61
|
+
* </button>
|
|
62
|
+
* )}
|
|
63
|
+
* </div>
|
|
64
|
+
* );
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export function useUser(signer, options = {}) {
|
|
69
|
+
const { userAddress, protocolAddress, credentialHash, enabled = true, queryOptions = {}, } = options;
|
|
70
|
+
const queryClient = useQueryClient();
|
|
71
|
+
// Create user client instance
|
|
72
|
+
const user = useMemo(() => {
|
|
73
|
+
if (!signer)
|
|
74
|
+
return null;
|
|
75
|
+
try {
|
|
76
|
+
return new UserClient(signer);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
console.warn('UserClient not available:', error);
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}, [signer]);
|
|
83
|
+
// Note: userAddress is used directly in queries below
|
|
84
|
+
// Query: Get protocol requirements
|
|
85
|
+
const { data: protocolRequirements, isLoading: isLoadingRequirements, error: requirementsError, refetch: refetchRequirements, } = useQuery({
|
|
86
|
+
queryKey: ['user', 'protocol-requirements', protocolAddress],
|
|
87
|
+
queryFn: async () => {
|
|
88
|
+
if (!user || !protocolAddress) {
|
|
89
|
+
throw new Error('User client or protocol address not available');
|
|
90
|
+
}
|
|
91
|
+
return user.getProtocolRequirements(protocolAddress);
|
|
92
|
+
},
|
|
93
|
+
enabled: enabled && !!user && !!protocolAddress,
|
|
94
|
+
...queryOptions,
|
|
95
|
+
});
|
|
96
|
+
// Note: To check user access, use the useProtocol hook instead
|
|
97
|
+
// This is because access checking is a protocol-level operation
|
|
98
|
+
// Query: Check credential validity
|
|
99
|
+
const { data: isCredentialValid, isLoading: isLoadingCredential, error: credentialError, refetch: refetchCredential, } = useQuery({
|
|
100
|
+
queryKey: ['user', 'credential-validity', credentialHash],
|
|
101
|
+
queryFn: async () => {
|
|
102
|
+
if (!user || !credentialHash) {
|
|
103
|
+
throw new Error('User client or credential hash not available');
|
|
104
|
+
}
|
|
105
|
+
return user.checkCredentialValidity(credentialHash);
|
|
106
|
+
},
|
|
107
|
+
enabled: enabled && !!user && !!credentialHash,
|
|
108
|
+
...queryOptions,
|
|
109
|
+
});
|
|
110
|
+
// Mutation: Check credential validity
|
|
111
|
+
const checkCredentialValidityMutation = useMutation({
|
|
112
|
+
mutationFn: async (credentialHash) => {
|
|
113
|
+
if (!user) {
|
|
114
|
+
throw new Error('User client not available');
|
|
115
|
+
}
|
|
116
|
+
return user.checkCredentialValidity(credentialHash);
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
// Mutation: Generate proof
|
|
120
|
+
const generateProofMutation = useMutation({
|
|
121
|
+
mutationFn: async (params) => {
|
|
122
|
+
if (!user) {
|
|
123
|
+
throw new Error('User client not available');
|
|
124
|
+
}
|
|
125
|
+
return user.generateProof(params.credential, params.requirements);
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
// Mutation: Verify and grant access
|
|
129
|
+
const verifyAndGrantAccessMutation = useMutation({
|
|
130
|
+
mutationFn: async (params) => {
|
|
131
|
+
if (!user) {
|
|
132
|
+
throw new Error('User client not available');
|
|
133
|
+
}
|
|
134
|
+
// UserClient.verifyAndGrantAccess expects a ProofResult object
|
|
135
|
+
return user.verifyAndGrantAccess({
|
|
136
|
+
proof: params.proof,
|
|
137
|
+
publicSignals: params.publicSignals,
|
|
138
|
+
nullifier: params.nullifier,
|
|
139
|
+
packedFlags: params.packedFlags,
|
|
140
|
+
credentialHash: params.credentialHash,
|
|
141
|
+
success: true,
|
|
142
|
+
}, params.protocolAddress, params.userAddress);
|
|
143
|
+
},
|
|
144
|
+
onSuccess: () => {
|
|
145
|
+
// Invalidate and refetch access status
|
|
146
|
+
queryClient.invalidateQueries({
|
|
147
|
+
queryKey: ['user', 'access'],
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
return {
|
|
152
|
+
user,
|
|
153
|
+
protocolRequirements,
|
|
154
|
+
isLoadingRequirements,
|
|
155
|
+
requirementsError: requirementsError,
|
|
156
|
+
refetchRequirements: () => {
|
|
157
|
+
refetchRequirements();
|
|
158
|
+
},
|
|
159
|
+
isCredentialValid,
|
|
160
|
+
isLoadingCredential,
|
|
161
|
+
credentialError: credentialError,
|
|
162
|
+
refetchCredential: () => {
|
|
163
|
+
refetchCredential();
|
|
164
|
+
},
|
|
165
|
+
checkCredentialValidity: {
|
|
166
|
+
mutate: checkCredentialValidityMutation.mutate,
|
|
167
|
+
mutateAsync: checkCredentialValidityMutation.mutateAsync,
|
|
168
|
+
isLoading: checkCredentialValidityMutation.isPending,
|
|
169
|
+
error: checkCredentialValidityMutation.error,
|
|
170
|
+
reset: checkCredentialValidityMutation.reset,
|
|
171
|
+
},
|
|
172
|
+
generateProof: {
|
|
173
|
+
mutate: generateProofMutation.mutate,
|
|
174
|
+
mutateAsync: generateProofMutation.mutateAsync,
|
|
175
|
+
isLoading: generateProofMutation.isPending,
|
|
176
|
+
error: generateProofMutation.error,
|
|
177
|
+
reset: generateProofMutation.reset,
|
|
178
|
+
},
|
|
179
|
+
verifyAndGrantAccess: {
|
|
180
|
+
mutate: verifyAndGrantAccessMutation.mutate,
|
|
181
|
+
mutateAsync: verifyAndGrantAccessMutation.mutateAsync,
|
|
182
|
+
isLoading: verifyAndGrantAccessMutation.isPending,
|
|
183
|
+
error: verifyAndGrantAccessMutation.error,
|
|
184
|
+
reset: verifyAndGrantAccessMutation.reset,
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=useUser.js.map
|
|
@@ -0,0 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BAAuB,EAAE;YACvB,MAAM,EAAE,+BAA+B,CAAC,MAAM;YAC9C,WAAW,EAAE,+BAA+B,CAAC,WAAW;YACxD,SAAS,EAAE,+BAA+B,CAAC,SAAS;YACpD,KAAK,EAAE,+BAA+B,CAAC,KAAqB;YAC5D,KAAK,EAAE,+BAA+B,CAAC,KAAK;SAC7C;QACD,aAAa,EAAE;YACb,MAAM,EAAE,qBAAqB,CAAC,MAAM;YACpC,WAAW,EAAE,qBAAqB,CAAC,WAAW;YAC9C,SAAS,EAAE,qBAAqB,CAAC,SAAS;YAC1C,KAAK,EAAE,qBAAqB,CAAC,KAAqB;YAClD,KAAK,EAAE,qBAAqB,CAAC,KAAK;SACnC;QACD,oBAAoB,EAAE;YACpB,MAAM,EAAE,4BAA4B,CAAC,MAAM;YAC3C,WAAW,EAAE,4BAA4B,CAAC,WAAW;YACrD,SAAS,EAAE,4BAA4B,CAAC,SAAS;YACjD,KAAK,EAAE,4BAA4B,CAAC,KAAqB;YACzD,KAAK,EAAE,4BAA4B,CAAC,KAAK;SAC1C;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NOAH Protocol SDK
|
|
3
|
+
*
|
|
4
|
+
* TypeScript/JavaScript SDK for integrating NOAH's privacy-preserving KYC functionality
|
|
5
|
+
* into DeFi protocols and applications.
|
|
6
|
+
*/
|
|
7
|
+
export { NoahSDK, NoahError, NoahValidationError, NoahProverError } from './core/NoahSDK.js';
|
|
8
|
+
export { ContractClient } from './core/ContractClient.js';
|
|
9
|
+
export { APIClient } from './core/APIClient.js';
|
|
10
|
+
export { WalletAdapter } from './core/WalletAdapter.js';
|
|
11
|
+
export type { WalletAdapterConfig, WalletState, WalletType } from './core/WalletAdapter.js';
|
|
12
|
+
export { ProtocolClient } from './protocol/ProtocolClient.js';
|
|
13
|
+
export { RequirementsManager } from './protocol/RequirementsManager.js';
|
|
14
|
+
export { UserClient } from './user/UserClient.js';
|
|
15
|
+
export { ProofGenerator } from './user/ProofGenerator.js';
|
|
16
|
+
export type { Credential, ProofResult, UserClientConfig } from './user/UserClient.js';
|
|
17
|
+
export { IssuerClient } from './issuer/IssuerClient.js';
|
|
18
|
+
export { jurisdictionStringToHash, jurisdictionStringsToHashes, parseJurisdictions, } from './utils/jurisdiction.js';
|
|
19
|
+
export { generateCredentialHash, isValidCredentialHash, isValidAddress, toChecksumAddress, } from './utils/credentials.js';
|
|
20
|
+
export { parseTD3, validateCheckDigit, } from './utils/mrz.js';
|
|
21
|
+
export type { MRZData } from './utils/mrz.js';
|
|
22
|
+
export { OCRExtractor } from './utils/ocr.js';
|
|
23
|
+
export type { OCROutput } from './utils/ocr.js';
|
|
24
|
+
export { IdentityManager } from './utils/identity.js';
|
|
25
|
+
export type { IdentityProfile } from './utils/identity.js';
|
|
26
|
+
export type { ContractAddresses, Requirements, IssuerInfo, Proof, ZKProof, TransactionResult, ContractClientConfig, ProtocolClientConfig, SetRequirementsParams, VerifyUserAccessParams, CredentialIssuedEvent, AccessGrantedEvent, EventCallback, ContractEventPayload, CredentialData, CredentialHashResult, } from './utils/types.js';
|
|
27
|
+
export type { APIClientConfig, ProofGenerationData, ProofGenerationResult, AccessStatus, CredentialStatus, } from './core/APIClient.js';
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC7F,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,YAAY,EAAE,mBAAmB,EAAE,W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}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NOAH Protocol SDK
|
|
3
|
+
*
|
|
4
|
+
* TypeScript/JavaScript SDK for integrating NOAH's privacy-preserving KYC functionality
|
|
5
|
+
* into DeFi protocols and applications.
|
|
6
|
+
*/
|
|
7
|
+
// Core exports
|
|
8
|
+
export { NoahSDK, NoahError, NoahValidationError, NoahProverError } from './core/NoahSDK.js';
|
|
9
|
+
export { ContractClient } from './core/ContractClient.js';
|
|
10
|
+
export { APIClient } from './core/APIClient.js';
|
|
11
|
+
export { WalletAdapter } from './core/WalletAdapter.js';
|
|
12
|
+
// Protocol exports
|
|
13
|
+
export { ProtocolClient } from './protocol/ProtocolClient.js';
|
|
14
|
+
export { RequirementsManager } from './protocol/RequirementsManager.js';
|
|
15
|
+
// User exports
|
|
16
|
+
export { UserClient } from './user/UserClient.js';
|
|
17
|
+
export { ProofGenerator } from './user/ProofGenerator.js';
|
|
18
|
+
// Issuer exports
|
|
19
|
+
export { IssuerClient } from './issuer/IssuerClient.js';
|
|
20
|
+
// Utilities
|
|
21
|
+
export { jurisdictionStringToHash, jurisdictionStringsToHashes, parseJurisdictions, } from './utils/jurisdiction.js';
|
|
22
|
+
export { generateCredentialHash, isValidCredentialHash, isValidAddress, toChecksumAddress, } from './utils/credentials.js';
|
|
23
|
+
export { parseTD3, validateCheckDigit, } from './utils/mrz.js';
|
|
24
|
+
export { OCRExtractor } from './utils/ocr.js';
|
|
25
|
+
export { IdentityManager } from './utils/identity.js';
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAe;AACf,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC7F,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAGxD,mBAAmB;AACnB,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAExE,eAAe;AACf,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG1D,iBAAiB;AACjB,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,YAAY;AACZ,OAAO,EACL,wBAAwB,EACxB,2BAA2B,EAC3B,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,cAAc,EACd,iBAAiB,GAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,QAAQ,EACR,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { Signer } from 'ethers';
|
|
2
|
+
import type { TransactionResult, ContractAddresses } from '../utils/types';
|
|
3
|
+
/**
|
|
4
|
+
* IssuerClient configuration options
|
|
5
|
+
*/
|
|
6
|
+
export interface IssuerClientConfig {
|
|
7
|
+
apiBaseUrl?: string;
|
|
8
|
+
contractAddresses?: Partial<ContractAddresses>;
|
|
9
|
+
rpcUrl?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Credential status information
|
|
13
|
+
*/
|
|
14
|
+
export interface CredentialStatus {
|
|
15
|
+
isValid: boolean;
|
|
16
|
+
credentialHash: string;
|
|
17
|
+
isRevoked: boolean;
|
|
18
|
+
issuer?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* IssuerClient - High-level API for credential issuers
|
|
22
|
+
*
|
|
23
|
+
* Provides a simple interface for issuers to:
|
|
24
|
+
* - Register credentials on-chain
|
|
25
|
+
* - Revoke credentials
|
|
26
|
+
* - Check credential status
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import { IssuerClient } from '@noah-protocol/sdk';
|
|
31
|
+
* import { ethers } from 'ethers';
|
|
32
|
+
*
|
|
33
|
+
* const provider = new ethers.BrowserProvider(window.ethereum);
|
|
34
|
+
* const signer = await provider.getSigner();
|
|
35
|
+
* const issuer = new IssuerClient(signer, { apiBaseUrl: 'https://api.noah.xyz' });
|
|
36
|
+
*
|
|
37
|
+
* // Register credential
|
|
38
|
+
* await issuer.registerCredential(credentialHash, userAddress);
|
|
39
|
+
*
|
|
40
|
+
* // Revoke credential
|
|
41
|
+
* await issuer.revokeCredential(credentialHash);
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare class IssuerClient {
|
|
45
|
+
private signer;
|
|
46
|
+
private contractClient;
|
|
47
|
+
private apiClient;
|
|
48
|
+
/**
|
|
49
|
+
* Create a new IssuerClient instance
|
|
50
|
+
* @param signer - Ethers.js signer from issuer's wallet
|
|
51
|
+
* @param config - Optional configuration
|
|
52
|
+
*/
|
|
53
|
+
constructor(signer: Signer, config?: IssuerClientConfig);
|
|
54
|
+
/**
|
|
55
|
+
* Register a credential on-chain
|
|
56
|
+
*
|
|
57
|
+
* @param credentialHash - The credential hash to register (bytes32)
|
|
58
|
+
* @param userAddress - The user's wallet address
|
|
59
|
+
* @param useAPI - If true, use backend API (gasless). If false, use direct contract call.
|
|
60
|
+
* @returns Promise resolving to transaction result
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const tx = await issuer.registerCredential('0x1234...', '0x5678...');
|
|
65
|
+
* console.log('Transaction hash:', tx.transactionHash);
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
registerCredential(credentialHash: string, userAddress: string, useAPI?: boolean): Promise<TransactionResult>;
|
|
69
|
+
/**
|
|
70
|
+
* Revoke a credential
|
|
71
|
+
*
|
|
72
|
+
* @param credentialHash - The credential hash to revoke (bytes32)
|
|
73
|
+
* @param useAPI - If true, use backend API (gasless). If false, use direct contract call.
|
|
74
|
+
* @returns Promise resolving to transaction result
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const tx = await issuer.revokeCredential('0x1234...');
|
|
79
|
+
* console.log('Transaction hash:', tx.transactionHash);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
revokeCredential(credentialHash: string, useAPI?: boolean): Promise<TransactionResult>;
|
|
83
|
+
/**
|
|
84
|
+
* Check credential status
|
|
85
|
+
*
|
|
86
|
+
* @param credentialHash - The credential hash to check (bytes32)
|
|
87
|
+
* @returns Promise resolving to credential status information
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const status = await issuer.checkCredential('0x1234...');
|
|
92
|
+
* console.log('Is valid:', status.isValid);
|
|
93
|
+
* console.log('Is revoked:', status.isRevoked);
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
checkCredential(credentialHash: string): Promise<CredentialStatus>;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=IssuerClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IssuerClient.d.ts","sourceRoot":"","sources":["../../src/issuer/IssuerClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAI3E;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC/C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,SAAS,CAAY;IAE7B;;;;OAIG;gBACS,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,kBAAuB;IAoB3D;;;;;;;;;;;;;OAaG;IACG,kBAAkB,CACtB,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,MAAM,EACnB,MAAM,GAAE,OAAe,GACtB,OAAO,CAAC,iBAAiB,CAAC;IA4B7B;;;;;;;;;;;;OAYG;IACG,gBAAgB,CACpB,cAAc,EAAE,MAAM,EACtB,MAAM,GAAE,OAAe,GACtB,OAAO,CAAC,iBAAiB,CAAC;IAuB7B;;;;;;;;;;;;OAYG;IACG,eAAe,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAgCzE"}
|