@dfns/sdk 0.6.12 → 0.7.1-alpha.1
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/baseAuthApi.d.ts +1 -8
- package/dfnsApiClient.d.ts +1 -1
- package/dfnsAuthenticator.d.ts +2 -2
- package/dfnsDelegatedApiClient.d.ts +1 -1
- package/generated/auth/client.d.ts +0 -8
- package/generated/auth/client.js +0 -76
- package/generated/auth/delegatedClient.d.ts +0 -12
- package/generated/auth/delegatedClient.js +0 -162
- package/generated/auth/types.d.ts +3 -254
- package/generated/exchanges/types.d.ts +416 -2
- package/generated/keys/types.d.ts +0 -3
- package/generated/permissions/types.d.ts +2 -2
- package/generated/policies/types.d.ts +480 -9
- package/generated/staking/types.d.ts +0 -16
- package/generated/wallets/types.d.ts +624 -9
- package/package.json +2 -3
- package/types/generic.d.ts +4 -4
- package/utils/authToken.d.ts +5 -0
- package/utils/authToken.js +20 -0
- package/utils/fetch.js +5 -10
- package/utils/index.d.ts +0 -1
- package/utils/index.js +0 -1
- package/utils/nonce.d.ts +0 -1
- package/utils/nonce.js +0 -12
package/package.json
CHANGED
package/types/generic.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { CredentialSigner } from '../signer';
|
|
2
2
|
export type DfnsBaseApiOptions = {
|
|
3
|
-
appId: string;
|
|
4
|
-
/** Needs to be specified to use any endpoint that requires authentication */
|
|
5
|
-
authToken?: string;
|
|
6
3
|
/** Only needs to be specified when using another API environment */
|
|
7
4
|
baseUrl?: string;
|
|
8
|
-
|
|
5
|
+
/** Auth token needs to be specified to use any endpoint that requires authentication */
|
|
6
|
+
authToken?: string;
|
|
7
|
+
/** If orgId is specified, and an auth token is used, then before API requests are sent, a check will be performed that the auth token is indeed scoped to the expected org. That can be useful in the context of multi-org */
|
|
8
|
+
orgId?: string;
|
|
9
9
|
};
|
|
10
10
|
export type DfnsApiClientOptions = DfnsBaseApiOptions & {
|
|
11
11
|
/** Needs to be specified to use any endpoint that required User Action Signing flow */
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertAuthTokenIsSameOrg = exports.JWT_CUSTOM_DATA_CLAIM = void 0;
|
|
4
|
+
const base64_1 = require("./base64");
|
|
5
|
+
exports.JWT_CUSTOM_DATA_CLAIM = 'https://custom/app_metadata';
|
|
6
|
+
const assertAuthTokenIsSameOrg = ({ authToken, orgId }) => {
|
|
7
|
+
const tokenBody = authToken.split('.')?.[1] || '';
|
|
8
|
+
let decoded;
|
|
9
|
+
try {
|
|
10
|
+
decoded = JSON.parse((0, base64_1.fromBase64)(tokenBody).toString('utf-8'));
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
throw new Error('Provided auth token could not be properly parsed');
|
|
14
|
+
}
|
|
15
|
+
const tokenOrgId = decoded?.[exports.JWT_CUSTOM_DATA_CLAIM]?.['orgId'];
|
|
16
|
+
if (tokenOrgId !== orgId) {
|
|
17
|
+
throw new Error(`Provided auth token is not scoped to org ID ${orgId}`);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
exports.assertAuthTokenIsSameOrg = assertAuthTokenIsSameOrg;
|
package/utils/fetch.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.simpleFetch = exports.dfnsAuth = exports.catchPolicyPending = exports.errorHandler = exports.jsonSerializer = exports.fullUrl = void 0;
|
|
4
4
|
const cross_fetch_1 = require("cross-fetch");
|
|
5
|
-
const nonce_1 = require("./nonce");
|
|
6
5
|
const dfnsError_1 = require("../dfnsError");
|
|
7
6
|
const DEFAULT_DFNS_BASE_URL = 'https://api.dfns.io';
|
|
8
7
|
const package_json_1 = require("../package.json");
|
|
8
|
+
const authToken_1 = require("./authToken");
|
|
9
9
|
const fullUrl = (fetch) => {
|
|
10
10
|
return async (resource, options) => {
|
|
11
11
|
const baseUrl = options.apiOptions.baseUrl || DEFAULT_DFNS_BASE_URL;
|
|
@@ -60,22 +60,17 @@ const catchPolicyPending = (fetch) => {
|
|
|
60
60
|
exports.catchPolicyPending = catchPolicyPending;
|
|
61
61
|
const dfnsAuth = (fetch) => {
|
|
62
62
|
return async (resource, options) => {
|
|
63
|
-
const {
|
|
63
|
+
const { orgId, authToken } = options.apiOptions;
|
|
64
|
+
if (authToken && orgId) {
|
|
65
|
+
(0, authToken_1.assertAuthTokenIsSameOrg)({ orgId, authToken });
|
|
66
|
+
}
|
|
64
67
|
const authorization = authToken
|
|
65
68
|
? {
|
|
66
69
|
authorization: `Bearer ${authToken}`,
|
|
67
70
|
}
|
|
68
71
|
: {};
|
|
69
|
-
const dfnsAppSecret = appSecret
|
|
70
|
-
? {
|
|
71
|
-
'x-dfns-appsecret': appSecret,
|
|
72
|
-
}
|
|
73
|
-
: {};
|
|
74
72
|
options.headers = {
|
|
75
|
-
'x-dfns-appid': appId,
|
|
76
|
-
'x-dfns-nonce': (0, nonce_1.generateNonce)(),
|
|
77
73
|
'x-dfns-sdk-version': package_json_1.version,
|
|
78
|
-
...dfnsAppSecret,
|
|
79
74
|
...authorization,
|
|
80
75
|
...(options.headers ?? {}),
|
|
81
76
|
};
|
package/utils/index.d.ts
CHANGED
package/utils/index.js
CHANGED
|
@@ -19,7 +19,6 @@ __exportStar(require("./base64"), exports);
|
|
|
19
19
|
__exportStar(require("./bigint"), exports);
|
|
20
20
|
__exportStar(require("./crypto"), exports);
|
|
21
21
|
__exportStar(require("./fetch"), exports);
|
|
22
|
-
__exportStar(require("./nonce"), exports);
|
|
23
22
|
__exportStar(require("./string"), exports);
|
|
24
23
|
__exportStar(require("./url"), exports);
|
|
25
24
|
const generateRandom = (size) => {
|
package/utils/nonce.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const generateNonce: () => string;
|
package/utils/nonce.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateNonce = void 0;
|
|
4
|
-
const uuid_1 = require("uuid");
|
|
5
|
-
const base64_1 = require("./base64");
|
|
6
|
-
const generateNonce = () => {
|
|
7
|
-
return (0, base64_1.toBase64Url)(JSON.stringify({
|
|
8
|
-
uuid: (0, uuid_1.v4)(),
|
|
9
|
-
date: new Date().toISOString(),
|
|
10
|
-
}));
|
|
11
|
-
};
|
|
12
|
-
exports.generateNonce = generateNonce;
|