@blocklet/did-space-js 1.0.1 → 1.0.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/dist/commands/backup/post-app-backup.js +1 -1
- package/dist/commands/backup/put-app-backup.js +1 -1
- package/dist/commands/incremental-sync/sync-push.js +5 -5
- package/dist/commands/nft/put-nft-object.js +1 -1
- package/dist/commands/object/delete-object.js +2 -3
- package/dist/commands/object/get-object.js +2 -3
- package/dist/commands/object/list-object.js +2 -3
- package/dist/commands/object/list-objects.js +2 -3
- package/dist/commands/object/put-object.js +1 -1
- package/dist/commands/preview/delete-preview-object.js +1 -1
- package/dist/commands/preview/get-preview-object.js +1 -1
- package/dist/commands/preview/put-preview-object.js +1 -1
- package/dist/commands/restore/post-app-restore.js +1 -1
- package/dist/commands/restore/put-app-restore.js +1 -1
- package/dist/commands/space/head.js +1 -1
- package/dist/did-document/verify-document.d.ts +1 -1
- package/dist/did-document/verify-document.js +2 -2
- package/dist/meta/object/preview-object-command.d.ts +197 -10
- package/dist/security/request-signature.d.ts +4 -4
- package/dist/security/request-signature.js +7 -7
- package/package.json +12 -12
|
@@ -22,7 +22,7 @@ class PostAppBackupCommand extends base_1.BaseCommand {
|
|
|
22
22
|
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'backup');
|
|
23
23
|
const data = this.input;
|
|
24
24
|
const method = 'POST';
|
|
25
|
-
const { headers } = (0, security_1.signRequest)({
|
|
25
|
+
const { headers } = await (0, security_1.signRequest)({
|
|
26
26
|
url,
|
|
27
27
|
method,
|
|
28
28
|
data,
|
|
@@ -22,7 +22,7 @@ class PutAppBackupCommand extends base_1.BaseCommand {
|
|
|
22
22
|
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'backup');
|
|
23
23
|
const data = this.input;
|
|
24
24
|
const method = 'PUT';
|
|
25
|
-
const { headers } = (0, security_1.signRequest)({
|
|
25
|
+
const { headers } = await (0, security_1.signRequest)({
|
|
26
26
|
url,
|
|
27
27
|
method,
|
|
28
28
|
data,
|
|
@@ -16,7 +16,7 @@ const pick_1 = __importDefault(require("lodash/pick"));
|
|
|
16
16
|
const p_all_1 = __importDefault(require("p-all"));
|
|
17
17
|
const fs_extra_1 = require("fs-extra");
|
|
18
18
|
const mime_types_1 = __importDefault(require("mime-types"));
|
|
19
|
-
const promises_1 = require("stream/promises");
|
|
19
|
+
const promises_1 = require("node:stream/promises");
|
|
20
20
|
const object_1 = require("../object");
|
|
21
21
|
const logger_1 = require("../../libs/logger");
|
|
22
22
|
const delete_object_1 = require("../object/delete-object");
|
|
@@ -113,11 +113,11 @@ class IncrementalSyncPushCommand extends sync_base_1.IncrementalSyncBaseCommand
|
|
|
113
113
|
}
|
|
114
114
|
registerEvents() {
|
|
115
115
|
this.removeAllListeners();
|
|
116
|
-
this.on('sync.before', (input) => {
|
|
117
|
-
this.input?.onProgress?.(input);
|
|
116
|
+
this.on('sync.before', async (input) => {
|
|
117
|
+
await this.input?.onProgress?.(input);
|
|
118
118
|
});
|
|
119
|
-
this.on('sync.after', (input) => {
|
|
120
|
-
this.input?.onAfterUpload?.(input);
|
|
119
|
+
this.on('sync.after', async (input) => {
|
|
120
|
+
await this.input?.onAfterUpload?.(input);
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
123
|
async sync(syncObjects) {
|
|
@@ -102,7 +102,7 @@ class PutNftObjectCommand extends base_1.BaseCommand {
|
|
|
102
102
|
const formData = new form_data_1.default();
|
|
103
103
|
formData.append('data', streamForUpload);
|
|
104
104
|
formData.append('didDocument', JSON.stringify(didDocument));
|
|
105
|
-
const { headers } = (0, security_1.signRequest)({
|
|
105
|
+
const { headers } = await (0, security_1.signRequest)({
|
|
106
106
|
url,
|
|
107
107
|
method,
|
|
108
108
|
data: formData,
|
|
@@ -6,10 +6,10 @@ const core_1 = require("@did-space/core");
|
|
|
6
6
|
const base_1 = require("../base");
|
|
7
7
|
const security_1 = require("../../security");
|
|
8
8
|
class DeleteObjectCommand extends base_1.BaseCommand {
|
|
9
|
-
getAxiosRequestConfig() {
|
|
9
|
+
async getAxiosRequestConfig() {
|
|
10
10
|
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'object', this.getKey(this.input.key));
|
|
11
11
|
const method = 'DELETE';
|
|
12
|
-
const { headers } = (0, security_1.signRequest)({
|
|
12
|
+
const { headers } = await (0, security_1.signRequest)({
|
|
13
13
|
url,
|
|
14
14
|
method,
|
|
15
15
|
data: {},
|
|
@@ -24,7 +24,6 @@ class DeleteObjectCommand extends base_1.BaseCommand {
|
|
|
24
24
|
method,
|
|
25
25
|
headers,
|
|
26
26
|
};
|
|
27
|
-
// @ts-expect-error
|
|
28
27
|
return axiosRequestConfig;
|
|
29
28
|
}
|
|
30
29
|
resolveMiddleware(res) {
|
|
@@ -6,10 +6,10 @@ const core_1 = require("@did-space/core");
|
|
|
6
6
|
const base_1 = require("../base");
|
|
7
7
|
const security_1 = require("../../security");
|
|
8
8
|
class GetObjectCommand extends base_1.BaseCommand {
|
|
9
|
-
getAxiosRequestConfig() {
|
|
9
|
+
async getAxiosRequestConfig() {
|
|
10
10
|
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'object', this.getKey(this.input.key));
|
|
11
11
|
const method = 'GET';
|
|
12
|
-
const { headers } = (0, security_1.signRequest)({
|
|
12
|
+
const { headers } = await (0, security_1.signRequest)({
|
|
13
13
|
url,
|
|
14
14
|
method,
|
|
15
15
|
data: {},
|
|
@@ -28,7 +28,6 @@ class GetObjectCommand extends base_1.BaseCommand {
|
|
|
28
28
|
...headers,
|
|
29
29
|
},
|
|
30
30
|
};
|
|
31
|
-
// @ts-expect-error
|
|
32
31
|
return config;
|
|
33
32
|
}
|
|
34
33
|
resolveMiddleware(res) {
|
|
@@ -6,10 +6,10 @@ const ufo_1 = require("ufo");
|
|
|
6
6
|
const base_1 = require("../base");
|
|
7
7
|
const security_1 = require("../../security");
|
|
8
8
|
class ListObjectCommand extends base_1.BaseCommand {
|
|
9
|
-
getAxiosRequestConfig() {
|
|
9
|
+
async getAxiosRequestConfig() {
|
|
10
10
|
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'list', this.getKey(this.input.key));
|
|
11
11
|
const method = 'GET';
|
|
12
|
-
const { headers } = (0, security_1.signRequest)({
|
|
12
|
+
const { headers } = await (0, security_1.signRequest)({
|
|
13
13
|
url,
|
|
14
14
|
method,
|
|
15
15
|
data: {},
|
|
@@ -24,7 +24,6 @@ class ListObjectCommand extends base_1.BaseCommand {
|
|
|
24
24
|
method,
|
|
25
25
|
headers,
|
|
26
26
|
};
|
|
27
|
-
// @ts-expect-error
|
|
28
27
|
return config;
|
|
29
28
|
}
|
|
30
29
|
}
|
|
@@ -15,14 +15,14 @@ const security_1 = require("../../security");
|
|
|
15
15
|
const { name, version } = require('../../../package.json');
|
|
16
16
|
const debug = (0, debug_1.default)(`${name}@${version}:list-objects`);
|
|
17
17
|
class ListObjectsCommand extends base_1.BaseCommand {
|
|
18
|
-
getAxiosRequestConfig() {
|
|
18
|
+
async getAxiosRequestConfig() {
|
|
19
19
|
// TODO: 此处应该有 joi 校验
|
|
20
20
|
const options = (0, pick_1.default)(this.input, ['recursive', 'ignoreDirectories']);
|
|
21
21
|
const queryParams = (0, isEmpty_1.default)(options) ? '' : `?${querystring_1.default.stringify(options)}`;
|
|
22
22
|
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'lists', this.getKey(this.input.key), queryParams);
|
|
23
23
|
const method = 'GET';
|
|
24
24
|
debug('getAxiosRequestConfig.$url', url);
|
|
25
|
-
const { headers } = (0, security_1.signRequest)({
|
|
25
|
+
const { headers } = await (0, security_1.signRequest)({
|
|
26
26
|
url,
|
|
27
27
|
method,
|
|
28
28
|
data: {},
|
|
@@ -37,7 +37,6 @@ class ListObjectsCommand extends base_1.BaseCommand {
|
|
|
37
37
|
method,
|
|
38
38
|
headers,
|
|
39
39
|
};
|
|
40
|
-
// @ts-expect-error
|
|
41
40
|
return config;
|
|
42
41
|
}
|
|
43
42
|
}
|
|
@@ -29,7 +29,7 @@ class PutObjectCommand extends base_1.BaseCommand {
|
|
|
29
29
|
if (!(0, isEmpty_1.default)(this.input.metadata)) {
|
|
30
30
|
body.append('metadata', JSON.stringify(this.input.metadata));
|
|
31
31
|
}
|
|
32
|
-
const { headers } = (0, security_1.signRequest)({
|
|
32
|
+
const { headers } = await (0, security_1.signRequest)({
|
|
33
33
|
url,
|
|
34
34
|
method,
|
|
35
35
|
data: body,
|
|
@@ -16,7 +16,7 @@ class DeletePreviewObjectCommand extends base_1.BaseCommand {
|
|
|
16
16
|
this.input = await meta_1.GetPreviewObjectCommandInputSchema.parseAsync(this.input);
|
|
17
17
|
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'object', this.getKey((0, path_1.join)(this.input.key, '.meta/preview.yml')));
|
|
18
18
|
const method = 'DELETE';
|
|
19
|
-
const { headers } = (0, security_1.signRequest)({
|
|
19
|
+
const { headers } = await (0, security_1.signRequest)({
|
|
20
20
|
url,
|
|
21
21
|
method,
|
|
22
22
|
data: {},
|
|
@@ -20,7 +20,7 @@ class GetPreviewObjectCommand extends base_1.BaseCommand {
|
|
|
20
20
|
this.input = await meta_1.GetPreviewObjectCommandInputSchema.parseAsync(this.input);
|
|
21
21
|
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'object', this.getKey((0, path_1.join)(this.input.key, '.meta/preview.yml')));
|
|
22
22
|
const method = 'GET';
|
|
23
|
-
const { headers } = (0, security_1.signRequest)({
|
|
23
|
+
const { headers } = await (0, security_1.signRequest)({
|
|
24
24
|
url,
|
|
25
25
|
method,
|
|
26
26
|
data: {},
|
|
@@ -41,7 +41,7 @@ class PutPreviewObjectCommand extends base_1.BaseCommand {
|
|
|
41
41
|
if (!(0, isEmpty_1.default)(this.input.metadata)) {
|
|
42
42
|
data.append('metadata', JSON.stringify(this.input.metadata));
|
|
43
43
|
}
|
|
44
|
-
const { headers } = (0, security_1.signRequest)({
|
|
44
|
+
const { headers } = await (0, security_1.signRequest)({
|
|
45
45
|
url,
|
|
46
46
|
method,
|
|
47
47
|
data,
|
|
@@ -18,7 +18,7 @@ class PostAppRestoreCommand extends base_1.BaseCommand {
|
|
|
18
18
|
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'restore');
|
|
19
19
|
const data = this.input;
|
|
20
20
|
const method = 'POST';
|
|
21
|
-
const { headers } = (0, security_1.signRequest)({
|
|
21
|
+
const { headers } = await (0, security_1.signRequest)({
|
|
22
22
|
url,
|
|
23
23
|
method,
|
|
24
24
|
data,
|
|
@@ -22,7 +22,7 @@ class PutAppRestoreCommand extends base_1.BaseCommand {
|
|
|
22
22
|
const url = (0, ufo_1.joinURL)(this.context.endpoint, 'restore');
|
|
23
23
|
const data = this.input;
|
|
24
24
|
const method = 'PUT';
|
|
25
|
-
const { headers } = (0, security_1.signRequest)({
|
|
25
|
+
const { headers } = await (0, security_1.signRequest)({
|
|
26
26
|
url,
|
|
27
27
|
method,
|
|
28
28
|
data,
|
|
@@ -22,7 +22,7 @@ class HeadSpaceCommand extends base_1.BaseCommand {
|
|
|
22
22
|
async resolveMiddleware() {
|
|
23
23
|
const url = this.getUrl();
|
|
24
24
|
const method = 'HEAD';
|
|
25
|
-
const { headers } = (0, security_1.signRequest)({
|
|
25
|
+
const { headers } = await (0, security_1.signRequest)({
|
|
26
26
|
url,
|
|
27
27
|
method,
|
|
28
28
|
data: {},
|
|
@@ -7,4 +7,4 @@ import { DidDocument } from './did-document';
|
|
|
7
7
|
* @param {DidDocument} didDocument
|
|
8
8
|
* @return {*} {Promise<boolean>}
|
|
9
9
|
*/
|
|
10
|
-
export declare function verifyDidDocument(didDocument: DidDocument): void
|
|
10
|
+
export declare function verifyDidDocument(didDocument: DidDocument): Promise<void>;
|
|
@@ -18,14 +18,14 @@ const util_1 = require("@ocap/util");
|
|
|
18
18
|
* @param {DidDocument} didDocument
|
|
19
19
|
* @return {*} {Promise<boolean>}
|
|
20
20
|
*/
|
|
21
|
-
function verifyDidDocument(didDocument) {
|
|
21
|
+
async function verifyDidDocument(didDocument) {
|
|
22
22
|
const verificationMethod = (0, get_1.default)(didDocument, 'proof.verificationMethod');
|
|
23
23
|
const verifyInfo = didDocument.verificationMethod.find((item) => item.id === verificationMethod);
|
|
24
24
|
const owner = (0, wallet_1.fromPublicKey)(verifyInfo.publicKeyMultibase, (0, did_1.toTypeInfo)(didDocument.controller));
|
|
25
25
|
const cloned = (0, cloneDeep_1.default)(didDocument);
|
|
26
26
|
const signature = cloned.proof.jws;
|
|
27
27
|
delete cloned.proof.jws;
|
|
28
|
-
if (owner.verify((0, json_stable_stringify_1.default)(cloned), (0, util_1.fromBase64)(signature))
|
|
28
|
+
if (!(await owner.verify((0, json_stable_stringify_1.default)(cloned), (0, util_1.fromBase64)(signature)))) {
|
|
29
29
|
throw new Error('DID Document signature not valid');
|
|
30
30
|
}
|
|
31
31
|
if (!(0, did_1.isFromPublicKey)(didDocument.controller, verifyInfo.publicKeyMultibase)) {
|
|
@@ -10,15 +10,29 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
10
10
|
* @description 预览模板的数据
|
|
11
11
|
*/
|
|
12
12
|
data: z.ZodUnion<[z.ZodObject<z.objectUtil.extendShape<{
|
|
13
|
-
template: z.
|
|
13
|
+
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"discuss">, z.ZodLiteral<"blog">, z.ZodLiteral<"bookmark">, z.ZodLiteral<"project">]>;
|
|
14
|
+
did: z.ZodEffects<z.ZodString, string, string>;
|
|
15
|
+
}, {
|
|
16
|
+
template: z.ZodLiteral<"app">;
|
|
17
|
+
name: z.ZodString;
|
|
18
|
+
logo: z.ZodString;
|
|
19
|
+
}>, "strip", z.ZodTypeAny, {
|
|
20
|
+
template: "app";
|
|
21
|
+
did: string;
|
|
22
|
+
name: string;
|
|
23
|
+
logo: string;
|
|
24
|
+
}, {
|
|
25
|
+
template: "app";
|
|
26
|
+
did: string;
|
|
27
|
+
name: string;
|
|
28
|
+
logo: string;
|
|
29
|
+
}>, z.ZodObject<z.objectUtil.extendShape<{
|
|
30
|
+
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"discuss">, z.ZodLiteral<"blog">, z.ZodLiteral<"bookmark">, z.ZodLiteral<"project">]>;
|
|
14
31
|
did: z.ZodEffects<z.ZodString, string, string>;
|
|
15
32
|
}, {
|
|
16
33
|
template: z.ZodLiteral<"nft">;
|
|
17
34
|
name: z.ZodString;
|
|
18
35
|
image: z.ZodString;
|
|
19
|
-
/**
|
|
20
|
-
* @description 文件夹的路径,必须以 / 结尾
|
|
21
|
-
*/
|
|
22
36
|
chainHost: z.ZodString;
|
|
23
37
|
}>, "strip", z.ZodTypeAny, {
|
|
24
38
|
template: "nft";
|
|
@@ -33,7 +47,7 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
33
47
|
image: string;
|
|
34
48
|
chainHost: string;
|
|
35
49
|
}>, z.ZodObject<z.objectUtil.extendShape<{
|
|
36
|
-
template: z.
|
|
50
|
+
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"discuss">, z.ZodLiteral<"blog">, z.ZodLiteral<"bookmark">, z.ZodLiteral<"project">]>;
|
|
37
51
|
did: z.ZodEffects<z.ZodString, string, string>;
|
|
38
52
|
}, {
|
|
39
53
|
template: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"profile">>>;
|
|
@@ -53,7 +67,7 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
53
67
|
email: string;
|
|
54
68
|
template?: "profile";
|
|
55
69
|
}>, z.ZodObject<z.objectUtil.extendShape<{
|
|
56
|
-
template: z.
|
|
70
|
+
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"discuss">, z.ZodLiteral<"blog">, z.ZodLiteral<"bookmark">, z.ZodLiteral<"project">]>;
|
|
57
71
|
did: z.ZodEffects<z.ZodString, string, string>;
|
|
58
72
|
}, {
|
|
59
73
|
template: z.ZodLiteral<"passport">;
|
|
@@ -65,8 +79,8 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
65
79
|
issuedTo: z.ZodString;
|
|
66
80
|
verified: z.ZodBoolean;
|
|
67
81
|
}>, "strip", z.ZodTypeAny, {
|
|
68
|
-
type: string[];
|
|
69
82
|
template: "passport";
|
|
83
|
+
type: string[];
|
|
70
84
|
did: string;
|
|
71
85
|
image: string;
|
|
72
86
|
issuerDid: string;
|
|
@@ -75,8 +89,8 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
75
89
|
issuedTo: string;
|
|
76
90
|
verified: boolean;
|
|
77
91
|
}, {
|
|
78
|
-
type: string[];
|
|
79
92
|
template: "passport";
|
|
93
|
+
type: string[];
|
|
80
94
|
did: string;
|
|
81
95
|
image: string;
|
|
82
96
|
issuerDid: string;
|
|
@@ -84,6 +98,107 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
84
98
|
issuedAt: string;
|
|
85
99
|
issuedTo: string;
|
|
86
100
|
verified: boolean;
|
|
101
|
+
}>, z.ZodObject<z.objectUtil.extendShape<{
|
|
102
|
+
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"discuss">, z.ZodLiteral<"blog">, z.ZodLiteral<"bookmark">, z.ZodLiteral<"project">]>;
|
|
103
|
+
did: z.ZodEffects<z.ZodString, string, string>;
|
|
104
|
+
}, {
|
|
105
|
+
template: z.ZodLiteral<"discuss">;
|
|
106
|
+
title: z.ZodString;
|
|
107
|
+
tags: z.ZodArray<z.ZodString, "many">;
|
|
108
|
+
url: z.ZodString;
|
|
109
|
+
createdAt: z.ZodString;
|
|
110
|
+
}>, "strip", z.ZodTypeAny, {
|
|
111
|
+
template: "discuss";
|
|
112
|
+
did: string;
|
|
113
|
+
title: string;
|
|
114
|
+
tags: string[];
|
|
115
|
+
url: string;
|
|
116
|
+
createdAt: string;
|
|
117
|
+
}, {
|
|
118
|
+
template: "discuss";
|
|
119
|
+
did: string;
|
|
120
|
+
title: string;
|
|
121
|
+
tags: string[];
|
|
122
|
+
url: string;
|
|
123
|
+
createdAt: string;
|
|
124
|
+
}>, z.ZodObject<z.objectUtil.extendShape<{
|
|
125
|
+
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"discuss">, z.ZodLiteral<"blog">, z.ZodLiteral<"bookmark">, z.ZodLiteral<"project">]>;
|
|
126
|
+
did: z.ZodEffects<z.ZodString, string, string>;
|
|
127
|
+
}, {
|
|
128
|
+
template: z.ZodLiteral<"blog">;
|
|
129
|
+
title: z.ZodString;
|
|
130
|
+
image: z.ZodString;
|
|
131
|
+
tags: z.ZodArray<z.ZodString, "many">;
|
|
132
|
+
url: z.ZodString;
|
|
133
|
+
createdAt: z.ZodEffects<z.ZodString, string, string>;
|
|
134
|
+
}>, "strip", z.ZodTypeAny, {
|
|
135
|
+
template: "blog";
|
|
136
|
+
did: string;
|
|
137
|
+
title: string;
|
|
138
|
+
image: string;
|
|
139
|
+
tags: string[];
|
|
140
|
+
url: string;
|
|
141
|
+
createdAt: string;
|
|
142
|
+
}, {
|
|
143
|
+
template: "blog";
|
|
144
|
+
did: string;
|
|
145
|
+
title: string;
|
|
146
|
+
image: string;
|
|
147
|
+
tags: string[];
|
|
148
|
+
url: string;
|
|
149
|
+
createdAt: string;
|
|
150
|
+
}>, z.ZodObject<z.objectUtil.extendShape<{
|
|
151
|
+
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"discuss">, z.ZodLiteral<"blog">, z.ZodLiteral<"bookmark">, z.ZodLiteral<"project">]>;
|
|
152
|
+
did: z.ZodEffects<z.ZodString, string, string>;
|
|
153
|
+
}, {
|
|
154
|
+
template: z.ZodLiteral<"bookmark">;
|
|
155
|
+
title: z.ZodString;
|
|
156
|
+
image: z.ZodString;
|
|
157
|
+
tags: z.ZodArray<z.ZodString, "many">;
|
|
158
|
+
url: z.ZodString;
|
|
159
|
+
createdAt: z.ZodEffects<z.ZodString, string, string>;
|
|
160
|
+
}>, "strip", z.ZodTypeAny, {
|
|
161
|
+
template: "bookmark";
|
|
162
|
+
did: string;
|
|
163
|
+
title: string;
|
|
164
|
+
image: string;
|
|
165
|
+
tags: string[];
|
|
166
|
+
url: string;
|
|
167
|
+
createdAt: string;
|
|
168
|
+
}, {
|
|
169
|
+
template: "bookmark";
|
|
170
|
+
did: string;
|
|
171
|
+
title: string;
|
|
172
|
+
image: string;
|
|
173
|
+
tags: string[];
|
|
174
|
+
url: string;
|
|
175
|
+
createdAt: string;
|
|
176
|
+
}>, z.ZodObject<z.objectUtil.extendShape<{
|
|
177
|
+
template: z.ZodUnion<[z.ZodLiteral<"nft">, z.ZodLiteral<"profile">, z.ZodLiteral<"passport">, z.ZodLiteral<"discuss">, z.ZodLiteral<"blog">, z.ZodLiteral<"bookmark">, z.ZodLiteral<"project">]>;
|
|
178
|
+
did: z.ZodEffects<z.ZodString, string, string>;
|
|
179
|
+
}, {
|
|
180
|
+
template: z.ZodLiteral<"project">;
|
|
181
|
+
name: z.ZodString;
|
|
182
|
+
description: z.ZodOptional<z.ZodString>;
|
|
183
|
+
image: z.ZodString;
|
|
184
|
+
url: z.ZodString;
|
|
185
|
+
createdAt: z.ZodEffects<z.ZodString, string, string>;
|
|
186
|
+
}>, "strip", z.ZodTypeAny, {
|
|
187
|
+
template: "project";
|
|
188
|
+
did: string;
|
|
189
|
+
name: string;
|
|
190
|
+
image: string;
|
|
191
|
+
url: string;
|
|
192
|
+
createdAt: string;
|
|
193
|
+
description?: string;
|
|
194
|
+
}, {
|
|
195
|
+
template: "project";
|
|
196
|
+
did: string;
|
|
197
|
+
name: string;
|
|
198
|
+
image: string;
|
|
199
|
+
url: string;
|
|
200
|
+
createdAt: string;
|
|
201
|
+
description?: string;
|
|
87
202
|
}>]>;
|
|
88
203
|
/**
|
|
89
204
|
* @description 存储元数据
|
|
@@ -115,6 +230,11 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
115
230
|
}, "strip", z.ZodTypeAny, {
|
|
116
231
|
key?: string;
|
|
117
232
|
data?: {
|
|
233
|
+
template: "app";
|
|
234
|
+
did: string;
|
|
235
|
+
name: string;
|
|
236
|
+
logo: string;
|
|
237
|
+
} | {
|
|
118
238
|
template: "nft";
|
|
119
239
|
did: string;
|
|
120
240
|
name: string;
|
|
@@ -127,8 +247,8 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
127
247
|
fullname: string;
|
|
128
248
|
email: string;
|
|
129
249
|
} | {
|
|
130
|
-
type: string[];
|
|
131
250
|
template: "passport";
|
|
251
|
+
type: string[];
|
|
132
252
|
did: string;
|
|
133
253
|
image: string;
|
|
134
254
|
issuerDid: string;
|
|
@@ -136,6 +256,37 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
136
256
|
issuedAt: string;
|
|
137
257
|
issuedTo: string;
|
|
138
258
|
verified: boolean;
|
|
259
|
+
} | {
|
|
260
|
+
template: "discuss";
|
|
261
|
+
did: string;
|
|
262
|
+
title: string;
|
|
263
|
+
tags: string[];
|
|
264
|
+
url: string;
|
|
265
|
+
createdAt: string;
|
|
266
|
+
} | {
|
|
267
|
+
template: "blog";
|
|
268
|
+
did: string;
|
|
269
|
+
title: string;
|
|
270
|
+
image: string;
|
|
271
|
+
tags: string[];
|
|
272
|
+
url: string;
|
|
273
|
+
createdAt: string;
|
|
274
|
+
} | {
|
|
275
|
+
template: "bookmark";
|
|
276
|
+
did: string;
|
|
277
|
+
title: string;
|
|
278
|
+
image: string;
|
|
279
|
+
tags: string[];
|
|
280
|
+
url: string;
|
|
281
|
+
createdAt: string;
|
|
282
|
+
} | {
|
|
283
|
+
template: "project";
|
|
284
|
+
did: string;
|
|
285
|
+
name: string;
|
|
286
|
+
image: string;
|
|
287
|
+
url: string;
|
|
288
|
+
createdAt: string;
|
|
289
|
+
description?: string;
|
|
139
290
|
};
|
|
140
291
|
hash?: string;
|
|
141
292
|
metadata?: Record<string, any>;
|
|
@@ -148,6 +299,11 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
148
299
|
}, {
|
|
149
300
|
key?: string;
|
|
150
301
|
data?: {
|
|
302
|
+
template: "app";
|
|
303
|
+
did: string;
|
|
304
|
+
name: string;
|
|
305
|
+
logo: string;
|
|
306
|
+
} | {
|
|
151
307
|
template: "nft";
|
|
152
308
|
did: string;
|
|
153
309
|
name: string;
|
|
@@ -160,8 +316,8 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
160
316
|
email: string;
|
|
161
317
|
template?: "profile";
|
|
162
318
|
} | {
|
|
163
|
-
type: string[];
|
|
164
319
|
template: "passport";
|
|
320
|
+
type: string[];
|
|
165
321
|
did: string;
|
|
166
322
|
image: string;
|
|
167
323
|
issuerDid: string;
|
|
@@ -169,6 +325,37 @@ export declare const PutPreviewObjectCommandInputSchema: z.ZodObject<{
|
|
|
169
325
|
issuedAt: string;
|
|
170
326
|
issuedTo: string;
|
|
171
327
|
verified: boolean;
|
|
328
|
+
} | {
|
|
329
|
+
template: "discuss";
|
|
330
|
+
did: string;
|
|
331
|
+
title: string;
|
|
332
|
+
tags: string[];
|
|
333
|
+
url: string;
|
|
334
|
+
createdAt: string;
|
|
335
|
+
} | {
|
|
336
|
+
template: "blog";
|
|
337
|
+
did: string;
|
|
338
|
+
title: string;
|
|
339
|
+
image: string;
|
|
340
|
+
tags: string[];
|
|
341
|
+
url: string;
|
|
342
|
+
createdAt: string;
|
|
343
|
+
} | {
|
|
344
|
+
template: "bookmark";
|
|
345
|
+
did: string;
|
|
346
|
+
title: string;
|
|
347
|
+
image: string;
|
|
348
|
+
tags: string[];
|
|
349
|
+
url: string;
|
|
350
|
+
createdAt: string;
|
|
351
|
+
} | {
|
|
352
|
+
template: "project";
|
|
353
|
+
did: string;
|
|
354
|
+
name: string;
|
|
355
|
+
image: string;
|
|
356
|
+
url: string;
|
|
357
|
+
createdAt: string;
|
|
358
|
+
description?: string;
|
|
172
359
|
};
|
|
173
360
|
hash?: string;
|
|
174
361
|
metadata?: Record<string, any>;
|
|
@@ -7,7 +7,7 @@ type Headers = {
|
|
|
7
7
|
'x-app-delegation': string;
|
|
8
8
|
[key: string]: any;
|
|
9
9
|
};
|
|
10
|
-
declare function verifyDelegation(delegation: string, delegatee: WalletObject): string
|
|
10
|
+
declare function verifyDelegation(delegation: string, delegatee: WalletObject): Promise<string>;
|
|
11
11
|
declare function signRequest({ url, method, data, headers, wallet, delegation, }: {
|
|
12
12
|
url: string;
|
|
13
13
|
method: Method;
|
|
@@ -17,16 +17,16 @@ declare function signRequest({ url, method, data, headers, wallet, delegation, }
|
|
|
17
17
|
};
|
|
18
18
|
wallet: WalletObject;
|
|
19
19
|
delegation?: string;
|
|
20
|
-
}): {
|
|
20
|
+
}): Promise<{
|
|
21
21
|
url: string;
|
|
22
22
|
method: Method;
|
|
23
23
|
data: any;
|
|
24
24
|
headers: Headers;
|
|
25
|
-
}
|
|
25
|
+
}>;
|
|
26
26
|
declare function verifyRequest({ url, method, data, headers, }: {
|
|
27
27
|
url: string;
|
|
28
28
|
method: Method;
|
|
29
29
|
data: any;
|
|
30
30
|
headers: Headers;
|
|
31
|
-
}): string
|
|
31
|
+
}): Promise<string>;
|
|
32
32
|
export { signRequest, verifyRequest, verifyDelegation };
|
|
@@ -18,9 +18,9 @@ const debug_1 = __importDefault(require("debug"));
|
|
|
18
18
|
const logger_1 = require("../libs/logger");
|
|
19
19
|
const debug = (0, debug_1.default)('request-signature');
|
|
20
20
|
// verifyDelegation to get actual appDid
|
|
21
|
-
function verifyDelegation(delegation, delegatee) {
|
|
21
|
+
async function verifyDelegation(delegation, delegatee) {
|
|
22
22
|
const { from, to, userPk, permissions } = (0, jwt_1.decode)(delegation);
|
|
23
|
-
if (!(0, jwt_1.verify)(delegation, userPk)) {
|
|
23
|
+
if (!(await (0, jwt_1.verify)(delegation, userPk))) {
|
|
24
24
|
throw new Error('delegation is not valid');
|
|
25
25
|
}
|
|
26
26
|
if (!(0, did_1.isFromPublicKey)(from, userPk)) {
|
|
@@ -53,7 +53,7 @@ function getSignUrl({ url }) {
|
|
|
53
53
|
}
|
|
54
54
|
return signUrl;
|
|
55
55
|
}
|
|
56
|
-
function signRequest({ url, method, data, headers, wallet, delegation, }) {
|
|
56
|
+
async function signRequest({ url, method, data, headers, wallet, delegation, }) {
|
|
57
57
|
if ((0, isEmpty_1.default)(url)) {
|
|
58
58
|
throw new Error(`url(${url}) cannot be empty`);
|
|
59
59
|
}
|
|
@@ -61,7 +61,7 @@ function signRequest({ url, method, data, headers, wallet, delegation, }) {
|
|
|
61
61
|
throw new Error(`data(${data}) is not an object`);
|
|
62
62
|
}
|
|
63
63
|
if (delegation) {
|
|
64
|
-
verifyDelegation(delegation, wallet);
|
|
64
|
+
await verifyDelegation(delegation, wallet);
|
|
65
65
|
}
|
|
66
66
|
const signUrl = getSignUrl({ url });
|
|
67
67
|
// @ts-expect-error
|
|
@@ -88,7 +88,7 @@ function signRequest({ url, method, data, headers, wallet, delegation, }) {
|
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
exports.signRequest = signRequest;
|
|
91
|
-
function verifyRequest({ url, method, data, headers, }) {
|
|
91
|
+
async function verifyRequest({ url, method, data, headers, }) {
|
|
92
92
|
let appDid = headers['x-app-did'];
|
|
93
93
|
const appPk = headers['x-app-pk'];
|
|
94
94
|
const appToken = headers['x-app-token'];
|
|
@@ -108,11 +108,11 @@ function verifyRequest({ url, method, data, headers, }) {
|
|
|
108
108
|
if (!(0, did_1.isFromPublicKey)(appDid, appPk)) {
|
|
109
109
|
throw new Error(`appDid(${appDid}) and appPk(${appPk}) do not match`);
|
|
110
110
|
}
|
|
111
|
-
if (!(0, jwt_1.verify)(appToken, appPk)) {
|
|
111
|
+
if (!(await (0, jwt_1.verify)(appToken, appPk))) {
|
|
112
112
|
throw new Error(`appToken(${appToken}) is invalid`);
|
|
113
113
|
}
|
|
114
114
|
if (delegation) {
|
|
115
|
-
appDid = verifyDelegation(delegation, (0, wallet_1.fromPublicKey)(appPk, (0, did_1.toTypeInfo)(appDid)));
|
|
115
|
+
appDid = await verifyDelegation(delegation, (0, wallet_1.fromPublicKey)(appPk, (0, did_1.toTypeInfo)(appDid)));
|
|
116
116
|
}
|
|
117
117
|
const payload = (0, jwt_1.decode)(appToken, true);
|
|
118
118
|
if ((0, isUndefined_1.default)(payload.digest)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/did-space-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"link": "yarn link"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@arcblock/did": "^1.
|
|
33
|
-
"@arcblock/jwt": "^1.
|
|
34
|
-
"@arcblock/validator": "^1.
|
|
35
|
-
"@blocklet/env": "^1.16.
|
|
36
|
-
"@did-space/core": "^1.0.
|
|
37
|
-
"@ocap/mcrypto": "^1.
|
|
38
|
-
"@ocap/util": "^1.
|
|
39
|
-
"@ocap/wallet": "^1.
|
|
32
|
+
"@arcblock/did": "^1.19.2",
|
|
33
|
+
"@arcblock/jwt": "^1.19.2",
|
|
34
|
+
"@arcblock/validator": "^1.19.2",
|
|
35
|
+
"@blocklet/env": "^1.16.38-beta-20250108-235929-17742885",
|
|
36
|
+
"@did-space/core": "^1.0.2",
|
|
37
|
+
"@ocap/mcrypto": "^1.19.2",
|
|
38
|
+
"@ocap/util": "^1.19.2",
|
|
39
|
+
"@ocap/wallet": "^1.19.2",
|
|
40
40
|
"agentkeepalive": "^4.6.0",
|
|
41
41
|
"axios": "^1.7.9",
|
|
42
42
|
"base64-url": "^2.3.3",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"@types/jest": "^28.1.8",
|
|
66
66
|
"@types/js-yaml": "^4.0.9",
|
|
67
67
|
"@types/json-stable-stringify": "^1.1.0",
|
|
68
|
-
"@types/lodash": "^4.17.
|
|
68
|
+
"@types/lodash": "^4.17.14",
|
|
69
69
|
"@types/mime-types": "^2.1.4",
|
|
70
70
|
"@types/node": "18.19.31",
|
|
71
71
|
"@types/valid-url": "^1.0.7",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"ts-jest": "^28.0.8",
|
|
77
77
|
"typescript": "^4.9.5"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
80
|
-
}
|
|
79
|
+
"gitHead": "4a4a0e41044fa70b2cf5a95ca3317e13ebcee7bb"
|
|
80
|
+
}
|