@zkpassport/sdk 0.1.0 → 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 +20 -18
- package/dist/constants/index.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -6
- package/dist/json-rpc.d.ts +2 -2
- package/dist/json-rpc.js +2 -2
- package/dist/mobile.js +4 -4
- package/package.json +1 -1
- package/src/constants/index.ts +1 -1
- package/src/index.ts +10 -10
- package/src/json-rpc.ts +4 -4
- package/src/mobile.ts +5 -5
package/README.md
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
## Installation
|
|
4
4
|
|
|
5
5
|
```
|
|
6
|
-
npm install
|
|
6
|
+
npm install @zkpassport/sdk
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
## How to use
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
|
-
import { ZkPassport } from 'zkpassport
|
|
12
|
+
import { ZkPassport } from '@zkpassport/sdk'
|
|
13
13
|
|
|
14
14
|
// Replace with your domain
|
|
15
15
|
const zkPassport = new ZkPassport('demo.zkpassport.id')
|
|
@@ -57,45 +57,48 @@ onProofGenerated((result: ProofResult) => {
|
|
|
57
57
|
console.log('nationality', result.queryResult.nationality.disclose.result)
|
|
58
58
|
})
|
|
59
59
|
```
|
|
60
|
+
|
|
60
61
|
### Using with Next.js
|
|
61
62
|
|
|
62
|
-
You can integrate
|
|
63
|
+
You can integrate `@zkpassport/sdk` into a Next.js application by creating a backend API route and calling it from your frontend.
|
|
63
64
|
|
|
64
65
|
#### **Backend (API Route)**
|
|
65
66
|
|
|
66
67
|
**App Router:** `app/api/zkpassport/route.ts`
|
|
68
|
+
|
|
67
69
|
```typescript
|
|
68
|
-
import { NextResponse } from 'next/server'
|
|
69
|
-
import { ZkPassport } from 'zkpassport
|
|
70
|
+
import { NextResponse } from 'next/server'
|
|
71
|
+
import { ZkPassport } from '@zkpassport/sdk'
|
|
70
72
|
|
|
71
73
|
export async function GET() {
|
|
72
|
-
const zkPassport = new ZkPassport('demo.zkpassport.id')
|
|
74
|
+
const zkPassport = new ZkPassport('demo.zkpassport.id') // Replace with your domain
|
|
73
75
|
const queryBuilder = await zkPassport.request({
|
|
74
76
|
name: 'ZKpassport Demo',
|
|
75
77
|
logo: 'https://via.placeholder.com/150',
|
|
76
78
|
purpose: 'Verify user nationality and first name',
|
|
77
|
-
})
|
|
78
|
-
const { url } = queryBuilder.disclose('nationality').disclose('firstname').done()
|
|
79
|
-
return NextResponse.json({ url })
|
|
79
|
+
})
|
|
80
|
+
const { url } = queryBuilder.disclose('nationality').disclose('firstname').done()
|
|
81
|
+
return NextResponse.json({ url })
|
|
80
82
|
}
|
|
81
83
|
```
|
|
82
84
|
|
|
83
85
|
#### **Frontend Example**
|
|
84
86
|
|
|
85
87
|
**App Router:** `app/page.tsx`
|
|
88
|
+
|
|
86
89
|
```tsx
|
|
87
|
-
'use client'
|
|
88
|
-
import { useEffect, useState } from 'react'
|
|
90
|
+
'use client'
|
|
91
|
+
import { useEffect, useState } from 'react'
|
|
89
92
|
|
|
90
93
|
export default function Home() {
|
|
91
|
-
const [verificationUrl, setVerificationUrl] = useState<string | null>(null)
|
|
94
|
+
const [verificationUrl, setVerificationUrl] = useState<string | null>(null)
|
|
92
95
|
|
|
93
96
|
useEffect(() => {
|
|
94
97
|
fetch('/api/zkpassport')
|
|
95
|
-
.then(res => res.json())
|
|
96
|
-
.then(data => setVerificationUrl(data.url))
|
|
97
|
-
.catch(console.error)
|
|
98
|
-
}, [])
|
|
98
|
+
.then((res) => res.json())
|
|
99
|
+
.then((data) => setVerificationUrl(data.url))
|
|
100
|
+
.catch(console.error)
|
|
101
|
+
}, [])
|
|
99
102
|
|
|
100
103
|
return (
|
|
101
104
|
<div>
|
|
@@ -108,9 +111,8 @@ export default function Home() {
|
|
|
108
111
|
<p>Loading...</p>
|
|
109
112
|
)}
|
|
110
113
|
</div>
|
|
111
|
-
)
|
|
114
|
+
)
|
|
112
115
|
}
|
|
113
|
-
|
|
114
116
|
```
|
|
115
117
|
|
|
116
118
|
## Local installation
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DisclosableIDCredential, IDCredential, IDCredentialValue, NumericalIDCredential } from '
|
|
2
|
-
import { ProofResult } from '
|
|
3
|
-
export * from '
|
|
4
|
-
export * from '
|
|
1
|
+
import { DisclosableIDCredential, IDCredential, IDCredentialValue, NumericalIDCredential } from './types/credentials';
|
|
2
|
+
import { ProofResult } from './types/query-result';
|
|
3
|
+
export * from './constants';
|
|
4
|
+
export * from './types';
|
|
5
5
|
export declare class ZkPassport {
|
|
6
6
|
private domain;
|
|
7
7
|
private topicToConfig;
|
package/dist/index.js
CHANGED
|
@@ -69,10 +69,10 @@ var crypto_1 = require("crypto");
|
|
|
69
69
|
var i18n_iso_countries_1 = require("i18n-iso-countries");
|
|
70
70
|
//import { UltraHonkBackend, ProofData, CompiledCircuit } from '@noir-lang/backend_barretenberg'
|
|
71
71
|
var utils_1 = require("@noble/ciphers/utils");
|
|
72
|
-
var websocket_1 = require("
|
|
73
|
-
var json_rpc_1 = require("
|
|
74
|
-
var encryption_1 = require("
|
|
75
|
-
var logger_1 = __importDefault(require("
|
|
72
|
+
var websocket_1 = require("./websocket");
|
|
73
|
+
var json_rpc_1 = require("./json-rpc");
|
|
74
|
+
var encryption_1 = require("./encryption");
|
|
75
|
+
var logger_1 = __importDefault(require("./logger"));
|
|
76
76
|
(0, i18n_iso_countries_1.registerLocale)(require('i18n-iso-countries/langs/en.json'));
|
|
77
77
|
function normalizeCountry(country) {
|
|
78
78
|
var normalizedCountry;
|
|
@@ -91,8 +91,8 @@ function generalCompare(fnName, key, value, requestId, requestIdToConfig) {
|
|
|
91
91
|
var _a;
|
|
92
92
|
requestIdToConfig[requestId][key] = __assign(__assign({}, requestIdToConfig[requestId][key]), (_a = {}, _a[fnName] = value, _a));
|
|
93
93
|
}
|
|
94
|
-
__exportStar(require("
|
|
95
|
-
__exportStar(require("
|
|
94
|
+
__exportStar(require("./constants"), exports);
|
|
95
|
+
__exportStar(require("./types"), exports);
|
|
96
96
|
var ZkPassport = /** @class */ (function () {
|
|
97
97
|
function ZkPassport(_domain) {
|
|
98
98
|
this.topicToConfig = {};
|
package/dist/json-rpc.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { JsonRpcRequest, JsonRpcResponse } from '
|
|
2
|
-
import { WebSocketClient } from '
|
|
1
|
+
import { JsonRpcRequest, JsonRpcResponse } from './types/json-rpc';
|
|
2
|
+
import { WebSocketClient } from './websocket';
|
|
3
3
|
export declare function createJsonRpcRequest(method: string, params: any): JsonRpcRequest;
|
|
4
4
|
export declare function createEncryptedJsonRpcRequest(method: string, params: any, sharedSecret: Uint8Array, topic: string): Promise<JsonRpcRequest>;
|
|
5
5
|
export declare function sendEncryptedJsonRpcRequest(method: string, params: any, sharedSecret: Uint8Array, topic: string, wsClient: WebSocketClient): Promise<boolean>;
|
package/dist/json-rpc.js
CHANGED
|
@@ -44,8 +44,8 @@ exports.createEncryptedJsonRpcRequest = createEncryptedJsonRpcRequest;
|
|
|
44
44
|
exports.sendEncryptedJsonRpcRequest = sendEncryptedJsonRpcRequest;
|
|
45
45
|
exports.createJsonRpcResponse = createJsonRpcResponse;
|
|
46
46
|
var crypto_1 = require("crypto");
|
|
47
|
-
var encryption_1 = require("
|
|
48
|
-
var logger_1 = __importDefault(require("
|
|
47
|
+
var encryption_1 = require("./encryption");
|
|
48
|
+
var logger_1 = __importDefault(require("./logger"));
|
|
49
49
|
function createJsonRpcRequest(method, params) {
|
|
50
50
|
return {
|
|
51
51
|
jsonrpc: '2.0',
|
package/dist/mobile.js
CHANGED
|
@@ -41,10 +41,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
exports.ZkPassportProver = void 0;
|
|
43
43
|
var utils_1 = require("@noble/ciphers/utils");
|
|
44
|
-
var websocket_1 = require("
|
|
45
|
-
var json_rpc_1 = require("
|
|
46
|
-
var encryption_1 = require("
|
|
47
|
-
var logger_1 = __importDefault(require("
|
|
44
|
+
var websocket_1 = require("./websocket");
|
|
45
|
+
var json_rpc_1 = require("./json-rpc");
|
|
46
|
+
var encryption_1 = require("./encryption");
|
|
47
|
+
var logger_1 = __importDefault(require("./logger"));
|
|
48
48
|
var ZkPassportProver = /** @class */ (function () {
|
|
49
49
|
function ZkPassportProver() {
|
|
50
50
|
this.topicToKeyPair = {};
|
package/package.json
CHANGED
package/src/constants/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -6,16 +6,16 @@ import {
|
|
|
6
6
|
IDCredentialConfig,
|
|
7
7
|
IDCredentialValue,
|
|
8
8
|
NumericalIDCredential,
|
|
9
|
-
} from '
|
|
10
|
-
import { ProofResult } from '
|
|
11
|
-
import { CountryName } from '
|
|
9
|
+
} from './types/credentials'
|
|
10
|
+
import { ProofResult } from './types/query-result'
|
|
11
|
+
import { CountryName } from './types/countries'
|
|
12
12
|
//import { UltraHonkBackend, ProofData, CompiledCircuit } from '@noir-lang/backend_barretenberg'
|
|
13
13
|
import { bytesToHex } from '@noble/ciphers/utils'
|
|
14
|
-
import { getWebSocketClient, WebSocketClient } from '
|
|
15
|
-
import { createEncryptedJsonRpcRequest } from '
|
|
16
|
-
import { decrypt, generateECDHKeyPair, getSharedSecret } from '
|
|
17
|
-
import { JsonRpcRequest } from '
|
|
18
|
-
import logger from '
|
|
14
|
+
import { getWebSocketClient, WebSocketClient } from './websocket'
|
|
15
|
+
import { createEncryptedJsonRpcRequest } from './json-rpc'
|
|
16
|
+
import { decrypt, generateECDHKeyPair, getSharedSecret } from './encryption'
|
|
17
|
+
import { JsonRpcRequest } from './types/json-rpc'
|
|
18
|
+
import logger from './logger'
|
|
19
19
|
|
|
20
20
|
registerLocale(require('i18n-iso-countries/langs/en.json'))
|
|
21
21
|
|
|
@@ -64,8 +64,8 @@ function generalCompare(
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
export * from '
|
|
68
|
-
export * from '
|
|
67
|
+
export * from './constants'
|
|
68
|
+
export * from './types'
|
|
69
69
|
|
|
70
70
|
export class ZkPassport {
|
|
71
71
|
private domain: string
|
package/src/json-rpc.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { randomBytes } from 'crypto'
|
|
2
|
-
import { JsonRpcRequest, JsonRpcResponse } from '
|
|
3
|
-
import { encrypt } from '
|
|
4
|
-
import { WebSocketClient } from '
|
|
5
|
-
import logger from '
|
|
2
|
+
import { JsonRpcRequest, JsonRpcResponse } from './types/json-rpc'
|
|
3
|
+
import { encrypt } from './encryption'
|
|
4
|
+
import { WebSocketClient } from './websocket'
|
|
5
|
+
import logger from './logger'
|
|
6
6
|
|
|
7
7
|
export function createJsonRpcRequest(method: string, params: any): JsonRpcRequest {
|
|
8
8
|
return {
|
package/src/mobile.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { bytesToHex } from '@noble/ciphers/utils'
|
|
2
|
-
import { getWebSocketClient, WebSocketClient } from '
|
|
3
|
-
import { sendEncryptedJsonRpcRequest } from '
|
|
4
|
-
import { decrypt, generateECDHKeyPair, getSharedSecret } from '
|
|
5
|
-
import { JsonRpcRequest } from '
|
|
6
|
-
import logger from '
|
|
2
|
+
import { getWebSocketClient, WebSocketClient } from './websocket'
|
|
3
|
+
import { sendEncryptedJsonRpcRequest } from './json-rpc'
|
|
4
|
+
import { decrypt, generateECDHKeyPair, getSharedSecret } from './encryption'
|
|
5
|
+
import { JsonRpcRequest } from './types/json-rpc'
|
|
6
|
+
import logger from './logger'
|
|
7
7
|
|
|
8
8
|
export class ZkPassportProver {
|
|
9
9
|
private domain?: string
|