@credenza3/partner-sdk 0.0.0-alpha.0 → 0.0.0-alpha.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 +29 -2
- package/dist/common/common.js +45 -0
- package/dist/{general → common}/index.d.ts +1 -1
- package/dist/{general → common}/index.js +1 -1
- package/dist/common/passport-id/passport-id.d.ts +6 -0
- package/dist/common/passport-id/passport-id.js +24 -0
- package/dist/evm/account/account.js +8 -19
- package/dist/sui/account/account.js +8 -19
- package/dist/sui/index.js +13 -1
- package/dist/sui/zk/account/account.js +8 -19
- package/dist/sui/zk/zk.js +8 -19
- package/package.json +18 -6
- package/dist/general/general.js +0 -56
- package/dist/general/passport-id/passport-id.d.ts +0 -1
- package/dist/general/passport-id/passport-id.js +0 -35
- /package/dist/{general/general.d.ts → common/common.d.ts} +0 -0
- /package/dist/{general → common}/passport-id/index.d.ts +0 -0
- /package/dist/{general → common}/passport-id/index.js +0 -0
package/README.md
CHANGED
|
@@ -1,2 +1,29 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# @credenza3/partner-sdk
|
|
2
|
+
|
|
3
|
+
## USAGE
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npm install @credenza3/partner-sdk
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
import { useAuth, useEnv } from '@credenza3/partner-sdk'
|
|
11
|
+
|
|
12
|
+
useEnv('prod' | 'staging' | 'local') // 'prod'
|
|
13
|
+
|
|
14
|
+
useAuth({
|
|
15
|
+
clientId: string,
|
|
16
|
+
clientSecret: string,
|
|
17
|
+
})
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## MODULES
|
|
21
|
+
|
|
22
|
+
[common](./src/common/README.md)
|
|
23
|
+
|
|
24
|
+
[evm](./src/evm/README.md)
|
|
25
|
+
|
|
26
|
+
[sui](./src/sui/README.md)
|
|
27
|
+
|
|
28
|
+
[sui/zk](./src/sui/zk/README.md)
|
|
29
|
+
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGeneralApiUrl = getGeneralApiUrl;
|
|
4
|
+
exports.getGeneralWsUrl = getGeneralWsUrl;
|
|
5
|
+
exports.getWsConnection = getWsConnection;
|
|
6
|
+
const sdk_env_1 = require("../lib/sdk-env");
|
|
7
|
+
const socket_io_client_1 = require("socket.io-client");
|
|
8
|
+
const credentials_1 = require("../lib/credentials");
|
|
9
|
+
let socket;
|
|
10
|
+
function getGeneralApiUrl() {
|
|
11
|
+
switch ((0, sdk_env_1.getSdkEnv)()) {
|
|
12
|
+
case sdk_env_1.SDK_ENV.PROD:
|
|
13
|
+
return 'https://api.credenza3.com';
|
|
14
|
+
case sdk_env_1.SDK_ENV.STAGING:
|
|
15
|
+
return 'https://api.staging.credenza.com';
|
|
16
|
+
case sdk_env_1.SDK_ENV.LOCAL:
|
|
17
|
+
return 'http://localhost:8084';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function getGeneralWsUrl() {
|
|
21
|
+
switch ((0, sdk_env_1.getSdkEnv)()) {
|
|
22
|
+
case sdk_env_1.SDK_ENV.PROD:
|
|
23
|
+
return 'wss://api.credenza3.com';
|
|
24
|
+
case sdk_env_1.SDK_ENV.STAGING:
|
|
25
|
+
return 'wss://api.staging.credenza.com';
|
|
26
|
+
case sdk_env_1.SDK_ENV.LOCAL:
|
|
27
|
+
return 'ws://localhost:8084';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function getWsConnection() {
|
|
31
|
+
const credentials = (0, credentials_1.getCredentials)();
|
|
32
|
+
if (!socket?.connected) {
|
|
33
|
+
socket = (0, socket_io_client_1.io)(getGeneralWsUrl(), {
|
|
34
|
+
auth: {
|
|
35
|
+
client_id: credentials.clientId,
|
|
36
|
+
client_secret: credentials.clientSecret,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
await new Promise((resolve, reject) => {
|
|
40
|
+
socket.once('connect', () => resolve(socket));
|
|
41
|
+
setTimeout(() => reject(new Error('Cannot connect to websocket server')), 5000);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return socket;
|
|
45
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './common';
|
|
2
2
|
export * from './passport-id';
|
|
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./common"), exports);
|
|
18
18
|
__exportStar(require("./passport-id"), exports);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requestPassportIdSignature = requestPassportIdSignature;
|
|
4
|
+
const common_1 = require("../../common");
|
|
5
|
+
async function requestPassportIdSignature(sub, message) {
|
|
6
|
+
if (!sub)
|
|
7
|
+
throw new Error('"Sub is required"');
|
|
8
|
+
if (!message)
|
|
9
|
+
throw new Error('"Message is required"');
|
|
10
|
+
const socket = await (0, common_1.getWsConnection)();
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
socket.once(`passport_id/signed/${sub}`, (data) => resolve(data));
|
|
13
|
+
socket.emit('passport_id/request_signature', {
|
|
14
|
+
payload: { sub, message },
|
|
15
|
+
}, (data) => {
|
|
16
|
+
if (!data.payload.ok) {
|
|
17
|
+
reject(new Error('Failed to sign message'));
|
|
18
|
+
}
|
|
19
|
+
if (data.error) {
|
|
20
|
+
reject(new Error(data.error.message));
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -1,26 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getEvmAddress = getEvmAddress;
|
|
13
4
|
const credentials_1 = require("../../lib/credentials");
|
|
14
5
|
const evm_1 = require("../../evm");
|
|
15
|
-
function getEvmAddress(sub) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
const json = yield response.json();
|
|
24
|
-
return json;
|
|
6
|
+
async function getEvmAddress(sub) {
|
|
7
|
+
const response = await fetch(`${(0, evm_1.getEvmApiUrl)()}/accounts/${sub}/address`, {
|
|
8
|
+
headers: {
|
|
9
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
10
|
+
'Content-Type': 'application/json',
|
|
11
|
+
},
|
|
25
12
|
});
|
|
13
|
+
const json = await response.json();
|
|
14
|
+
return json;
|
|
26
15
|
}
|
|
@@ -1,26 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getSuiAddress = getSuiAddress;
|
|
13
4
|
const credentials_1 = require("../../lib/credentials");
|
|
14
5
|
const sui_1 = require("../../sui");
|
|
15
|
-
function getSuiAddress(sub) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
const json = yield response.json();
|
|
24
|
-
return json;
|
|
6
|
+
async function getSuiAddress(sub) {
|
|
7
|
+
const response = await fetch(`${(0, sui_1.getSuiApiUrl)()}/accounts/${sub}/address`, {
|
|
8
|
+
headers: {
|
|
9
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
10
|
+
'Content-Type': 'application/json',
|
|
11
|
+
},
|
|
25
12
|
});
|
|
13
|
+
const json = await response.json();
|
|
14
|
+
return json;
|
|
26
15
|
}
|
package/dist/sui/index.js
CHANGED
|
@@ -10,10 +10,22 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
13
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
20
|
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
16
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
29
|
exports.zk = void 0;
|
|
18
30
|
__exportStar(require("./sui"), exports);
|
|
19
|
-
exports.zk = require("./zk");
|
|
31
|
+
exports.zk = __importStar(require("./zk"));
|
|
@@ -1,26 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getSuiZkAddress = getSuiZkAddress;
|
|
13
4
|
const credentials_1 = require("../../../lib/credentials");
|
|
14
5
|
const sui_1 = require("../../../sui");
|
|
15
|
-
function getSuiZkAddress(sub) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
const json = yield response.json();
|
|
24
|
-
return json;
|
|
6
|
+
async function getSuiZkAddress(sub) {
|
|
7
|
+
const response = await fetch(`${(0, sui_1.getSuiApiUrl)()}/accounts/zk/${sub}/address`, {
|
|
8
|
+
headers: {
|
|
9
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
10
|
+
'Content-Type': 'application/json',
|
|
11
|
+
},
|
|
25
12
|
});
|
|
13
|
+
const json = await response.json();
|
|
14
|
+
return json;
|
|
26
15
|
}
|
package/dist/sui/zk/zk.js
CHANGED
|
@@ -1,26 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getSuiZkAddress = getSuiZkAddress;
|
|
13
4
|
const credentials_1 = require("../../lib/credentials");
|
|
14
5
|
const sui_1 = require("../sui");
|
|
15
|
-
function getSuiZkAddress(sub) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
const json = yield response.json();
|
|
24
|
-
return json;
|
|
6
|
+
async function getSuiZkAddress(sub) {
|
|
7
|
+
const response = await fetch(`${(0, sui_1.getSuiApiUrl)()}/accounts/zk/${sub}/address`, {
|
|
8
|
+
headers: {
|
|
9
|
+
Authorization: (0, credentials_1.getBasicToken)(),
|
|
10
|
+
'Content-Type': 'application/json',
|
|
11
|
+
},
|
|
25
12
|
});
|
|
13
|
+
const json = await response.json();
|
|
14
|
+
return json;
|
|
26
15
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@credenza3/partner-sdk",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.2",
|
|
4
4
|
"description": "Credenza partner sdk",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,10 +10,22 @@
|
|
|
10
10
|
},
|
|
11
11
|
"author": "Credenza (Dmytro Fokin)",
|
|
12
12
|
"exports": {
|
|
13
|
-
"./sui":
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
"./sui": {
|
|
14
|
+
"node": "./dist/sui/index.js",
|
|
15
|
+
"types": "./dist/sui/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./evm": {
|
|
18
|
+
"node": "./dist/evm/index.js",
|
|
19
|
+
"types": "./dist/evm/index.d.ts"
|
|
20
|
+
},
|
|
21
|
+
"./common": {
|
|
22
|
+
"node": "./dist/common/index.js",
|
|
23
|
+
"types": "./dist/common/index.d.ts"
|
|
24
|
+
},
|
|
25
|
+
".": {
|
|
26
|
+
"node": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts"
|
|
28
|
+
}
|
|
17
29
|
},
|
|
18
30
|
"files": [
|
|
19
31
|
"/dist"
|
|
@@ -37,7 +49,7 @@
|
|
|
37
49
|
"scripts": {
|
|
38
50
|
"build": "tsc && tsc-alias",
|
|
39
51
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
40
|
-
"lint": "eslint --fix --max-warnings 0",
|
|
52
|
+
"lint": "eslint \"src/**/*.ts\" --fix --max-warnings 0",
|
|
41
53
|
"test": "echo \"Error: no test specified\"",
|
|
42
54
|
"pre-commit-lint": "lint-staged",
|
|
43
55
|
"demo": "pnpm run build && cd ./demo && pnpm run start",
|
package/dist/general/general.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getGeneralApiUrl = getGeneralApiUrl;
|
|
13
|
-
exports.getGeneralWsUrl = getGeneralWsUrl;
|
|
14
|
-
exports.getWsConnection = getWsConnection;
|
|
15
|
-
const sdk_env_1 = require("../lib/sdk-env");
|
|
16
|
-
const socket_io_client_1 = require("socket.io-client");
|
|
17
|
-
const credentials_1 = require("../lib/credentials");
|
|
18
|
-
let socket;
|
|
19
|
-
function getGeneralApiUrl() {
|
|
20
|
-
switch ((0, sdk_env_1.getSdkEnv)()) {
|
|
21
|
-
case sdk_env_1.SDK_ENV.PROD:
|
|
22
|
-
return 'https://api.credenza3.com';
|
|
23
|
-
case sdk_env_1.SDK_ENV.STAGING:
|
|
24
|
-
return 'https://api.staging.credenza.com';
|
|
25
|
-
case sdk_env_1.SDK_ENV.LOCAL:
|
|
26
|
-
return 'http://localhost:8084';
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function getGeneralWsUrl() {
|
|
30
|
-
switch ((0, sdk_env_1.getSdkEnv)()) {
|
|
31
|
-
case sdk_env_1.SDK_ENV.PROD:
|
|
32
|
-
return 'wss://api.credenza3.com';
|
|
33
|
-
case sdk_env_1.SDK_ENV.STAGING:
|
|
34
|
-
return 'wss://api.staging.credenza.com';
|
|
35
|
-
case sdk_env_1.SDK_ENV.LOCAL:
|
|
36
|
-
return 'ws://localhost:8084';
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function getWsConnection() {
|
|
40
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
const credentials = (0, credentials_1.getCredentials)();
|
|
42
|
-
if (!(socket === null || socket === void 0 ? void 0 : socket.connected)) {
|
|
43
|
-
socket = (0, socket_io_client_1.io)(getGeneralWsUrl(), {
|
|
44
|
-
auth: {
|
|
45
|
-
client_id: credentials.clientId,
|
|
46
|
-
client_secret: credentials.clientSecret,
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
yield new Promise((resolve, reject) => {
|
|
50
|
-
socket.once('connect', () => resolve(socket));
|
|
51
|
-
setTimeout(() => reject(new Error('Cannot connect to websocket server')), 5000);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
return socket;
|
|
55
|
-
});
|
|
56
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function requestPassportIdSignature(sub: string, message: string): Promise<unknown>;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.requestPassportIdSignature = requestPassportIdSignature;
|
|
13
|
-
const general_1 = require("../../general");
|
|
14
|
-
function requestPassportIdSignature(sub, message) {
|
|
15
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
if (!sub)
|
|
17
|
-
throw new Error('"Sub is required"');
|
|
18
|
-
if (!message)
|
|
19
|
-
throw new Error('"Message is required"');
|
|
20
|
-
const socket = yield (0, general_1.getWsConnection)();
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
socket.once(`passport_id/signed/${sub}`, (data) => resolve(data));
|
|
23
|
-
socket.emit('passport_id/request_signature', {
|
|
24
|
-
payload: { sub, message },
|
|
25
|
-
}, (data) => {
|
|
26
|
-
if (!data.payload.ok) {
|
|
27
|
-
reject(new Error('Failed to sign message'));
|
|
28
|
-
}
|
|
29
|
-
if (data.error) {
|
|
30
|
-
reject(new Error(data.error.message));
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|