@arcblock/nft 1.28.8 → 1.29.0
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 +0 -1
- package/esm/enum.d.mts +23 -0
- package/esm/enum.mjs +22 -0
- package/esm/factory.d.mts +141 -0
- package/esm/factory.mjs +310 -0
- package/esm/index.d.mts +5 -0
- package/esm/index.mjs +6 -0
- package/esm/issuer.d.mts +44 -0
- package/esm/issuer.mjs +36 -0
- package/esm/package.mjs +5 -0
- package/esm/recipient.d.mts +40 -0
- package/esm/recipient.mjs +34 -0
- package/lib/_virtual/rolldown_runtime.cjs +29 -0
- package/lib/enum.cjs +24 -0
- package/lib/enum.d.cts +23 -0
- package/lib/factory.cjs +319 -0
- package/lib/factory.d.cts +141 -0
- package/lib/index.cjs +10 -0
- package/lib/index.d.cts +5 -0
- package/lib/issuer.cjs +38 -0
- package/lib/issuer.d.cts +44 -0
- package/lib/package.cjs +11 -0
- package/lib/recipient.cjs +36 -0
- package/lib/recipient.d.cts +40 -0
- package/package.json +41 -15
- package/lib/enum.d.ts +0 -18
- package/lib/enum.js +0 -21
- package/lib/factory.d.ts +0 -165
- package/lib/factory.js +0 -398
- package/lib/index.d.ts +0 -259
- package/lib/index.js +0 -12
- package/lib/issuer.d.ts +0 -31
- package/lib/issuer.js +0 -25
- package/lib/recipient.d.ts +0 -27
- package/lib/recipient.js +0 -24
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
|
|
29
|
+
exports.__toESM = __toESM;
|
package/lib/enum.cjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/enum.ts
|
|
3
|
+
const NFTType = Object.freeze({
|
|
4
|
+
ticket: 0,
|
|
5
|
+
coupon: 1,
|
|
6
|
+
certificate: 2,
|
|
7
|
+
badge: 3,
|
|
8
|
+
license: 4,
|
|
9
|
+
giftcard: 5,
|
|
10
|
+
passport: 6,
|
|
11
|
+
idcard: 7,
|
|
12
|
+
receipt: 8,
|
|
13
|
+
other: 127
|
|
14
|
+
});
|
|
15
|
+
const NFTStatus = Object.freeze({
|
|
16
|
+
normal: 0,
|
|
17
|
+
consumed: 1,
|
|
18
|
+
invalid: 2,
|
|
19
|
+
expired: 3
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.NFTStatus = NFTStatus;
|
|
24
|
+
exports.NFTType = NFTType;
|
package/lib/enum.d.cts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/enum.d.ts
|
|
2
|
+
declare const NFTType: Readonly<{
|
|
3
|
+
readonly ticket: 0;
|
|
4
|
+
readonly coupon: 1;
|
|
5
|
+
readonly certificate: 2;
|
|
6
|
+
readonly badge: 3;
|
|
7
|
+
readonly license: 4;
|
|
8
|
+
readonly giftcard: 5;
|
|
9
|
+
readonly passport: 6;
|
|
10
|
+
readonly idcard: 7;
|
|
11
|
+
readonly receipt: 8;
|
|
12
|
+
readonly other: 127;
|
|
13
|
+
}>;
|
|
14
|
+
declare const NFTStatus: Readonly<{
|
|
15
|
+
readonly normal: 0;
|
|
16
|
+
readonly consumed: 1;
|
|
17
|
+
readonly invalid: 2;
|
|
18
|
+
readonly expired: 3;
|
|
19
|
+
}>;
|
|
20
|
+
type NFTTypeKey = keyof typeof NFTType;
|
|
21
|
+
type NFTStatusKey = keyof typeof NFTStatus;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { NFTStatus, NFTStatusKey, NFTType, NFTTypeKey };
|
package/lib/factory.cjs
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
3
|
+
const require_issuer = require('./issuer.cjs');
|
|
4
|
+
const require_recipient = require('./recipient.cjs');
|
|
5
|
+
const require_package = require('./package.cjs');
|
|
6
|
+
let _arcblock_did_util = require("@arcblock/did-util");
|
|
7
|
+
let _arcblock_vc = require("@arcblock/vc");
|
|
8
|
+
let _ocap_client = require("@ocap/client");
|
|
9
|
+
_ocap_client = require_rolldown_runtime.__toESM(_ocap_client);
|
|
10
|
+
let _ocap_util = require("@ocap/util");
|
|
11
|
+
let _ocap_wallet = require("@ocap/wallet");
|
|
12
|
+
let debug = require("debug");
|
|
13
|
+
debug = require_rolldown_runtime.__toESM(debug);
|
|
14
|
+
let json_stable_stringify = require("json-stable-stringify");
|
|
15
|
+
json_stable_stringify = require_rolldown_runtime.__toESM(json_stable_stringify);
|
|
16
|
+
let lodash_cloneDeep = require("lodash/cloneDeep");
|
|
17
|
+
lodash_cloneDeep = require_rolldown_runtime.__toESM(lodash_cloneDeep);
|
|
18
|
+
let lodash_get = require("lodash/get");
|
|
19
|
+
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
20
|
+
let lodash_isDate = require("lodash/isDate");
|
|
21
|
+
lodash_isDate = require_rolldown_runtime.__toESM(lodash_isDate);
|
|
22
|
+
let lodash_isNumber = require("lodash/isNumber");
|
|
23
|
+
lodash_isNumber = require_rolldown_runtime.__toESM(lodash_isNumber);
|
|
24
|
+
|
|
25
|
+
//#region src/factory.ts
|
|
26
|
+
const debug$1 = (0, debug.default)(require_package.name);
|
|
27
|
+
/**
|
|
28
|
+
* Used to create standard asset on forge powered blockchain
|
|
29
|
+
* All assets are signed assets, eg, the asset data are self approvable
|
|
30
|
+
*/
|
|
31
|
+
var NFTFactory = class {
|
|
32
|
+
/**
|
|
33
|
+
* Creates an instance of NFTFactory.
|
|
34
|
+
* @param params - Factory parameters
|
|
35
|
+
* @param params.chainHost - on which chain to create wallet
|
|
36
|
+
* @param params.wallet - issuer wallet
|
|
37
|
+
* @param params.issuer - issuer attributes, such as name, url and logo
|
|
38
|
+
*/
|
|
39
|
+
constructor({ chainHost, wallet, issuer }) {
|
|
40
|
+
if (!chainHost) throw new Error("NFTFactory requires valid chain host");
|
|
41
|
+
if ((0, _ocap_wallet.isValid)(wallet) === false) throw new Error("NFTFactory requires valid wallet issuer");
|
|
42
|
+
this.chainHost = chainHost;
|
|
43
|
+
this.client = new _ocap_client.default(chainHost);
|
|
44
|
+
this.wallet = wallet;
|
|
45
|
+
this.issuer = new require_issuer.default({
|
|
46
|
+
wallet,
|
|
47
|
+
...issuer
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Create a ticket
|
|
52
|
+
*
|
|
53
|
+
* @param params - Ticket parameters
|
|
54
|
+
* @param params.display - display of the ticket { type, content }
|
|
55
|
+
* @param params.data - asset payload
|
|
56
|
+
* @param params.attributes - asset attributes
|
|
57
|
+
* @returns Promise resolving to [asset, hash]
|
|
58
|
+
*/
|
|
59
|
+
async createTicket({ display = "", data = {}, attributes = {} }) {
|
|
60
|
+
const requiredFields = [
|
|
61
|
+
"name",
|
|
62
|
+
"description",
|
|
63
|
+
"location"
|
|
64
|
+
];
|
|
65
|
+
const timeFields = ["startTime", "endTime"];
|
|
66
|
+
requiredFields.forEach((x) => {
|
|
67
|
+
if (!data[x]) throw new Error(`Missing required field ${x} when creating ticket asset`);
|
|
68
|
+
});
|
|
69
|
+
timeFields.forEach((x) => {
|
|
70
|
+
if (!(0, lodash_isDate.default)(new Date(data[x]))) throw new Error(`Invalid date field ${x} when creating ticket asset`);
|
|
71
|
+
});
|
|
72
|
+
const { name: name$1, description, location, recipient, type, startTime, endTime, display: innerDisplay = "", issuanceDate } = data;
|
|
73
|
+
if (!(recipient instanceof require_recipient.default)) throw new Error(`Invalid recipient field when creating ${type} asset`);
|
|
74
|
+
const vc = await (0, _arcblock_vc.create)({
|
|
75
|
+
type: [
|
|
76
|
+
type,
|
|
77
|
+
"NFTTicket",
|
|
78
|
+
"VerifiableCredential"
|
|
79
|
+
].filter(Boolean),
|
|
80
|
+
issuer: {
|
|
81
|
+
wallet: this.wallet,
|
|
82
|
+
name: this.issuer.attributes.name
|
|
83
|
+
},
|
|
84
|
+
subject: {
|
|
85
|
+
id: recipient.wallet.address,
|
|
86
|
+
name: name$1,
|
|
87
|
+
description,
|
|
88
|
+
location,
|
|
89
|
+
display: this._createDisplay(display || innerDisplay),
|
|
90
|
+
startTime: new Date(startTime),
|
|
91
|
+
endTime: new Date(endTime)
|
|
92
|
+
},
|
|
93
|
+
issuanceDate: issuanceDate || /* @__PURE__ */ new Date(),
|
|
94
|
+
expirationDate: new Date(endTime)
|
|
95
|
+
});
|
|
96
|
+
debug$1("createTicket.vc", vc);
|
|
97
|
+
return this.createSignedAsset(vc, attributes);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Create a coupon asset
|
|
101
|
+
*
|
|
102
|
+
* @param params - Coupon parameters
|
|
103
|
+
* @param params.display - display of the coupon { type, content }
|
|
104
|
+
* @param params.data - asset payload
|
|
105
|
+
* @param params.attributes - asset attributes
|
|
106
|
+
* @returns Promise resolving to [asset, hash]
|
|
107
|
+
*/
|
|
108
|
+
async createCoupon({ display = "", data = {}, attributes = {} }) {
|
|
109
|
+
const requiredFields = ["name", "description"];
|
|
110
|
+
const numberFields = [
|
|
111
|
+
"ratio",
|
|
112
|
+
"amount",
|
|
113
|
+
"minAmount"
|
|
114
|
+
];
|
|
115
|
+
const timeFields = ["startTime", "expireTime"];
|
|
116
|
+
requiredFields.forEach((x) => {
|
|
117
|
+
if (!data[x]) throw new Error(`Missing required field ${x} when creating coupon asset`);
|
|
118
|
+
});
|
|
119
|
+
numberFields.forEach((x) => {
|
|
120
|
+
if (!data[x] || !(0, lodash_isNumber.default)(data[x])) throw new Error(`Invalid number field ${x} when creating coupon asset`);
|
|
121
|
+
});
|
|
122
|
+
timeFields.forEach((x) => {
|
|
123
|
+
if (!(0, lodash_isDate.default)(new Date(data[x]))) throw new Error(`Invalid date field ${x} when creating coupon asset`);
|
|
124
|
+
});
|
|
125
|
+
const { name: name$1, description, ratio, amount, location, minAmount, expireTime, type, recipient, display: innerDisplay = "", issuanceDate, endpoint, endpointScope } = data;
|
|
126
|
+
const vc = await (0, _arcblock_vc.create)({
|
|
127
|
+
type: [
|
|
128
|
+
type,
|
|
129
|
+
"NFTCoupon",
|
|
130
|
+
"VerifiableCredential"
|
|
131
|
+
].filter(Boolean),
|
|
132
|
+
issuer: {
|
|
133
|
+
wallet: this.issuer.wallet,
|
|
134
|
+
name: this.issuer.attributes.name
|
|
135
|
+
},
|
|
136
|
+
subject: {
|
|
137
|
+
id: recipient.wallet.address,
|
|
138
|
+
name: name$1,
|
|
139
|
+
description,
|
|
140
|
+
location,
|
|
141
|
+
ratio,
|
|
142
|
+
amount,
|
|
143
|
+
minAmount,
|
|
144
|
+
display: this._createDisplay(display || innerDisplay)
|
|
145
|
+
},
|
|
146
|
+
endpoint,
|
|
147
|
+
endpointScope,
|
|
148
|
+
issuanceDate: issuanceDate || /* @__PURE__ */ new Date(),
|
|
149
|
+
expirationDate: new Date(expireTime)
|
|
150
|
+
});
|
|
151
|
+
debug$1("createTicket.coupon", vc);
|
|
152
|
+
return this.createSignedAsset(vc, attributes);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Create a certificate asset
|
|
156
|
+
*
|
|
157
|
+
* @param params - Certificate parameters
|
|
158
|
+
* @param params.display - display of the certificate { type, content }
|
|
159
|
+
* @param params.data - asset payload
|
|
160
|
+
* @param params.attributes - asset attributes
|
|
161
|
+
* @returns Promise resolving to [asset, hash]
|
|
162
|
+
*/
|
|
163
|
+
createCertificate({ display = "", data = {}, attributes = {} }) {
|
|
164
|
+
return this._createCert({
|
|
165
|
+
data,
|
|
166
|
+
display,
|
|
167
|
+
attributes
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Create a badge
|
|
172
|
+
*
|
|
173
|
+
* @param params - Badge parameters
|
|
174
|
+
* @param params.display - display of the badge { type, content }
|
|
175
|
+
* @param params.data - asset payload
|
|
176
|
+
* @param params.attributes - asset attributes
|
|
177
|
+
* @returns Promise resolving to [asset, hash]
|
|
178
|
+
*/
|
|
179
|
+
async createBadge({ display = "", data = {}, attributes = {} }) {
|
|
180
|
+
const { name: name$1, recipient, description, display: innerDisplay = "", type, endpoint, endpointScope } = data;
|
|
181
|
+
const vc = await (0, _arcblock_vc.create)({
|
|
182
|
+
type: [
|
|
183
|
+
type,
|
|
184
|
+
"NFTBadge",
|
|
185
|
+
"VerifiableCredential"
|
|
186
|
+
].filter(Boolean),
|
|
187
|
+
issuer: {
|
|
188
|
+
wallet: this.wallet,
|
|
189
|
+
name: this.issuer.attributes.name
|
|
190
|
+
},
|
|
191
|
+
subject: {
|
|
192
|
+
id: recipient.wallet.address,
|
|
193
|
+
name: name$1,
|
|
194
|
+
description,
|
|
195
|
+
display: this._createDisplay(display || innerDisplay)
|
|
196
|
+
},
|
|
197
|
+
endpoint,
|
|
198
|
+
endpointScope
|
|
199
|
+
});
|
|
200
|
+
return this.createSignedAsset(vc, attributes);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Create a passport
|
|
204
|
+
*
|
|
205
|
+
* @param params - Passport parameters
|
|
206
|
+
* @param params.display - display of the passport { type, content }
|
|
207
|
+
* @param params.data - asset payload
|
|
208
|
+
* @param params.attributes - asset attributes
|
|
209
|
+
* @returns Promise resolving to [asset, hash]
|
|
210
|
+
*/
|
|
211
|
+
async createPassport({ display = "", data = {}, attributes = {} }) {
|
|
212
|
+
const { recipient, passport, display: innerDisplay = "", type, endpoint, endpointScope } = data;
|
|
213
|
+
const passportData = passport;
|
|
214
|
+
if (!passportData || !passportData.name || !passportData.title) throw new Error("NFTPassport requires valid passport object: which must have a name and a title");
|
|
215
|
+
const vc = await (0, _arcblock_vc.create)({
|
|
216
|
+
type: [
|
|
217
|
+
type,
|
|
218
|
+
"NFTPassport",
|
|
219
|
+
"VerifiableCredential"
|
|
220
|
+
].filter(Boolean),
|
|
221
|
+
issuer: {
|
|
222
|
+
wallet: this.wallet,
|
|
223
|
+
name: this.issuer.attributes.name
|
|
224
|
+
},
|
|
225
|
+
subject: {
|
|
226
|
+
id: recipient.wallet.address,
|
|
227
|
+
passport,
|
|
228
|
+
display: this._createDisplay(display || innerDisplay)
|
|
229
|
+
},
|
|
230
|
+
endpoint,
|
|
231
|
+
endpointScope
|
|
232
|
+
});
|
|
233
|
+
return this.createSignedAsset(vc, attributes);
|
|
234
|
+
}
|
|
235
|
+
async createSignedAsset(payload, attributes) {
|
|
236
|
+
payload.signature = (0, _ocap_util.toBase58)(await this.wallet.sign((0, json_stable_stringify.default)(payload)));
|
|
237
|
+
const asset = {
|
|
238
|
+
moniker: (0, lodash_get.default)(payload, "data.name") || (0, lodash_get.default)(payload, "credentialSubject.name") || "signed_asset",
|
|
239
|
+
readonly: false,
|
|
240
|
+
transferrable: true,
|
|
241
|
+
data: {
|
|
242
|
+
typeUrl: "vc",
|
|
243
|
+
value: payload
|
|
244
|
+
},
|
|
245
|
+
...attributes
|
|
246
|
+
};
|
|
247
|
+
asset.address = (0, _arcblock_did_util.toAssetAddress)(asset);
|
|
248
|
+
return [asset, await this.client.sendCreateAssetTx({
|
|
249
|
+
tx: { itx: asset },
|
|
250
|
+
wallet: this.wallet
|
|
251
|
+
})];
|
|
252
|
+
}
|
|
253
|
+
_createDisplay(display) {
|
|
254
|
+
if (display) {
|
|
255
|
+
if (typeof display === "string") return {
|
|
256
|
+
type: "svg_gzipped",
|
|
257
|
+
content: display
|
|
258
|
+
};
|
|
259
|
+
return display;
|
|
260
|
+
}
|
|
261
|
+
return {};
|
|
262
|
+
}
|
|
263
|
+
async _createCert({ display = "", data = {}, attributes = {} }) {
|
|
264
|
+
const requiredFields = [
|
|
265
|
+
"name",
|
|
266
|
+
"description",
|
|
267
|
+
"reason",
|
|
268
|
+
"logoUrl"
|
|
269
|
+
];
|
|
270
|
+
const timeFields = ["issueTime", "expireTime"];
|
|
271
|
+
requiredFields.forEach((x) => {
|
|
272
|
+
if (!data[x]) throw new Error(`Missing required field ${x} when creating certificate`);
|
|
273
|
+
});
|
|
274
|
+
timeFields.forEach((x) => {
|
|
275
|
+
if (!(0, lodash_isDate.default)(new Date(data[x]))) throw new Error(`Invalid date field ${x} when creating certificate`);
|
|
276
|
+
});
|
|
277
|
+
if (!(data.recipient instanceof require_recipient.default)) throw new Error("Invalid recipient field when creating certificate");
|
|
278
|
+
const { name: name$1, description, reason, logoUrl, recipient, type, expireTime, display: innerDisplay = "", issuanceDate, endpoint, endpointScope } = data;
|
|
279
|
+
const vc = await (0, _arcblock_vc.create)({
|
|
280
|
+
type: [
|
|
281
|
+
type,
|
|
282
|
+
"NFTCertificate",
|
|
283
|
+
"VerifiableCredential"
|
|
284
|
+
].filter(Boolean),
|
|
285
|
+
issuer: {
|
|
286
|
+
wallet: this.wallet,
|
|
287
|
+
name: this.issuer.attributes.name
|
|
288
|
+
},
|
|
289
|
+
subject: {
|
|
290
|
+
id: recipient.wallet.address,
|
|
291
|
+
name: name$1,
|
|
292
|
+
description,
|
|
293
|
+
reason,
|
|
294
|
+
logoUrl,
|
|
295
|
+
display: this._createDisplay(display || innerDisplay)
|
|
296
|
+
},
|
|
297
|
+
endpoint,
|
|
298
|
+
endpointScope,
|
|
299
|
+
issuanceDate: issuanceDate || /* @__PURE__ */ new Date(),
|
|
300
|
+
expirationDate: +new Date(expireTime)
|
|
301
|
+
});
|
|
302
|
+
debug$1("createCert.vc", vc);
|
|
303
|
+
return this.createSignedAsset(vc, attributes);
|
|
304
|
+
}
|
|
305
|
+
getVCBody(asset) {
|
|
306
|
+
if (!asset.data) return null;
|
|
307
|
+
if (!asset.data.typeUrl) return null;
|
|
308
|
+
if (asset.data.typeUrl === "vc") {
|
|
309
|
+
const vc = (0, lodash_cloneDeep.default)(asset.data.value);
|
|
310
|
+
delete vc.signature;
|
|
311
|
+
return vc;
|
|
312
|
+
}
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
var factory_default = NFTFactory;
|
|
317
|
+
|
|
318
|
+
//#endregion
|
|
319
|
+
exports.default = factory_default;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import NFTIssuer from "./issuer.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/factory.d.ts
|
|
4
|
+
interface WalletObject {
|
|
5
|
+
address: string;
|
|
6
|
+
publicKey: Uint8Array | string;
|
|
7
|
+
sign: (data: string) => Promise<Uint8Array | string>;
|
|
8
|
+
}
|
|
9
|
+
interface IssuerParams {
|
|
10
|
+
name: string;
|
|
11
|
+
url?: string;
|
|
12
|
+
logo?: string;
|
|
13
|
+
}
|
|
14
|
+
interface NFTFactoryParams {
|
|
15
|
+
chainHost: string;
|
|
16
|
+
wallet: WalletObject;
|
|
17
|
+
issuer: IssuerParams;
|
|
18
|
+
}
|
|
19
|
+
interface DisplayObject {
|
|
20
|
+
type?: string;
|
|
21
|
+
content?: string;
|
|
22
|
+
}
|
|
23
|
+
interface AssetData {
|
|
24
|
+
typeUrl: string;
|
|
25
|
+
value: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
interface Asset {
|
|
28
|
+
address?: string;
|
|
29
|
+
moniker: string;
|
|
30
|
+
readonly: boolean;
|
|
31
|
+
transferrable: boolean;
|
|
32
|
+
data: AssetData;
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
}
|
|
35
|
+
interface CreateParams {
|
|
36
|
+
display?: string | DisplayObject;
|
|
37
|
+
data?: Record<string, unknown>;
|
|
38
|
+
attributes?: Record<string, unknown>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Used to create standard asset on forge powered blockchain
|
|
42
|
+
* All assets are signed assets, eg, the asset data are self approvable
|
|
43
|
+
*/
|
|
44
|
+
declare class NFTFactory {
|
|
45
|
+
chainHost: string;
|
|
46
|
+
client: unknown;
|
|
47
|
+
wallet: WalletObject;
|
|
48
|
+
issuer: NFTIssuer;
|
|
49
|
+
/**
|
|
50
|
+
* Creates an instance of NFTFactory.
|
|
51
|
+
* @param params - Factory parameters
|
|
52
|
+
* @param params.chainHost - on which chain to create wallet
|
|
53
|
+
* @param params.wallet - issuer wallet
|
|
54
|
+
* @param params.issuer - issuer attributes, such as name, url and logo
|
|
55
|
+
*/
|
|
56
|
+
constructor({
|
|
57
|
+
chainHost,
|
|
58
|
+
wallet,
|
|
59
|
+
issuer
|
|
60
|
+
}: NFTFactoryParams);
|
|
61
|
+
/**
|
|
62
|
+
* Create a ticket
|
|
63
|
+
*
|
|
64
|
+
* @param params - Ticket parameters
|
|
65
|
+
* @param params.display - display of the ticket { type, content }
|
|
66
|
+
* @param params.data - asset payload
|
|
67
|
+
* @param params.attributes - asset attributes
|
|
68
|
+
* @returns Promise resolving to [asset, hash]
|
|
69
|
+
*/
|
|
70
|
+
createTicket({
|
|
71
|
+
display,
|
|
72
|
+
data,
|
|
73
|
+
attributes
|
|
74
|
+
}: CreateParams): Promise<[Asset, string]>;
|
|
75
|
+
/**
|
|
76
|
+
* Create a coupon asset
|
|
77
|
+
*
|
|
78
|
+
* @param params - Coupon parameters
|
|
79
|
+
* @param params.display - display of the coupon { type, content }
|
|
80
|
+
* @param params.data - asset payload
|
|
81
|
+
* @param params.attributes - asset attributes
|
|
82
|
+
* @returns Promise resolving to [asset, hash]
|
|
83
|
+
*/
|
|
84
|
+
createCoupon({
|
|
85
|
+
display,
|
|
86
|
+
data,
|
|
87
|
+
attributes
|
|
88
|
+
}: CreateParams): Promise<[Asset, string]>;
|
|
89
|
+
/**
|
|
90
|
+
* Create a certificate asset
|
|
91
|
+
*
|
|
92
|
+
* @param params - Certificate parameters
|
|
93
|
+
* @param params.display - display of the certificate { type, content }
|
|
94
|
+
* @param params.data - asset payload
|
|
95
|
+
* @param params.attributes - asset attributes
|
|
96
|
+
* @returns Promise resolving to [asset, hash]
|
|
97
|
+
*/
|
|
98
|
+
createCertificate({
|
|
99
|
+
display,
|
|
100
|
+
data,
|
|
101
|
+
attributes
|
|
102
|
+
}: CreateParams): Promise<[Asset, string]>;
|
|
103
|
+
/**
|
|
104
|
+
* Create a badge
|
|
105
|
+
*
|
|
106
|
+
* @param params - Badge parameters
|
|
107
|
+
* @param params.display - display of the badge { type, content }
|
|
108
|
+
* @param params.data - asset payload
|
|
109
|
+
* @param params.attributes - asset attributes
|
|
110
|
+
* @returns Promise resolving to [asset, hash]
|
|
111
|
+
*/
|
|
112
|
+
createBadge({
|
|
113
|
+
display,
|
|
114
|
+
data,
|
|
115
|
+
attributes
|
|
116
|
+
}: CreateParams): Promise<[Asset, string]>;
|
|
117
|
+
/**
|
|
118
|
+
* Create a passport
|
|
119
|
+
*
|
|
120
|
+
* @param params - Passport parameters
|
|
121
|
+
* @param params.display - display of the passport { type, content }
|
|
122
|
+
* @param params.data - asset payload
|
|
123
|
+
* @param params.attributes - asset attributes
|
|
124
|
+
* @returns Promise resolving to [asset, hash]
|
|
125
|
+
*/
|
|
126
|
+
createPassport({
|
|
127
|
+
display,
|
|
128
|
+
data,
|
|
129
|
+
attributes
|
|
130
|
+
}: CreateParams): Promise<[Asset, string]>;
|
|
131
|
+
createSignedAsset(payload: Record<string, unknown>, attributes: Record<string, unknown>): Promise<[Asset, string]>;
|
|
132
|
+
_createDisplay(display: string | DisplayObject): DisplayObject;
|
|
133
|
+
_createCert({
|
|
134
|
+
display,
|
|
135
|
+
data,
|
|
136
|
+
attributes
|
|
137
|
+
}: CreateParams): Promise<[Asset, string]>;
|
|
138
|
+
getVCBody(asset: Asset): Record<string, unknown> | null;
|
|
139
|
+
}
|
|
140
|
+
//#endregion
|
|
141
|
+
export { NFTFactory as default };
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const require_enum = require('./enum.cjs');
|
|
2
|
+
const require_issuer = require('./issuer.cjs');
|
|
3
|
+
const require_recipient = require('./recipient.cjs');
|
|
4
|
+
const require_factory = require('./factory.cjs');
|
|
5
|
+
|
|
6
|
+
exports.NFTFactory = require_factory.default;
|
|
7
|
+
exports.NFTIssuer = require_issuer.default;
|
|
8
|
+
exports.NFTRecipient = require_recipient.default;
|
|
9
|
+
exports.NFTStatus = require_enum.NFTStatus;
|
|
10
|
+
exports.NFTType = require_enum.NFTType;
|
package/lib/index.d.cts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { NFTStatus, NFTStatusKey, NFTType, NFTTypeKey } from "./enum.cjs";
|
|
2
|
+
import NFTIssuer from "./issuer.cjs";
|
|
3
|
+
import NFTFactory from "./factory.cjs";
|
|
4
|
+
import NFTRecipient from "./recipient.cjs";
|
|
5
|
+
export { NFTFactory, NFTIssuer, NFTRecipient, NFTStatus, type NFTStatusKey, NFTType, type NFTTypeKey };
|
package/lib/issuer.cjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
3
|
+
let _ocap_util = require("@ocap/util");
|
|
4
|
+
|
|
5
|
+
//#region src/issuer.ts
|
|
6
|
+
/**
|
|
7
|
+
* Represents an NFT issuer with wallet and metadata
|
|
8
|
+
*/
|
|
9
|
+
var NFTIssuer = class {
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of NFTIssuer.
|
|
12
|
+
*
|
|
13
|
+
* @param params - Issuer parameters
|
|
14
|
+
* @param params.wallet - wallet object
|
|
15
|
+
* @param params.name - issuer name
|
|
16
|
+
* @param params.url - issuer website
|
|
17
|
+
* @param params.logo - issuer logo image url or logo base64
|
|
18
|
+
*/
|
|
19
|
+
constructor({ wallet, name, url, logo }) {
|
|
20
|
+
this.wallet = wallet;
|
|
21
|
+
this.attributes = {
|
|
22
|
+
name,
|
|
23
|
+
url,
|
|
24
|
+
logo
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
toJSON() {
|
|
28
|
+
return {
|
|
29
|
+
did: this.wallet.address,
|
|
30
|
+
pk: (0, _ocap_util.toBase58)(this.wallet.publicKey),
|
|
31
|
+
...this.attributes
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var issuer_default = NFTIssuer;
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
exports.default = issuer_default;
|
package/lib/issuer.d.cts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//#region src/issuer.d.ts
|
|
2
|
+
interface IssuerAttributes {
|
|
3
|
+
name: string;
|
|
4
|
+
url?: string;
|
|
5
|
+
logo?: string;
|
|
6
|
+
}
|
|
7
|
+
interface WalletObject {
|
|
8
|
+
address: string;
|
|
9
|
+
publicKey: Uint8Array | string;
|
|
10
|
+
}
|
|
11
|
+
interface NFTIssuerParams extends IssuerAttributes {
|
|
12
|
+
wallet: WalletObject;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Represents an NFT issuer with wallet and metadata
|
|
16
|
+
*/
|
|
17
|
+
declare class NFTIssuer {
|
|
18
|
+
wallet: WalletObject;
|
|
19
|
+
attributes: IssuerAttributes;
|
|
20
|
+
/**
|
|
21
|
+
* Creates an instance of NFTIssuer.
|
|
22
|
+
*
|
|
23
|
+
* @param params - Issuer parameters
|
|
24
|
+
* @param params.wallet - wallet object
|
|
25
|
+
* @param params.name - issuer name
|
|
26
|
+
* @param params.url - issuer website
|
|
27
|
+
* @param params.logo - issuer logo image url or logo base64
|
|
28
|
+
*/
|
|
29
|
+
constructor({
|
|
30
|
+
wallet,
|
|
31
|
+
name,
|
|
32
|
+
url,
|
|
33
|
+
logo
|
|
34
|
+
}: NFTIssuerParams);
|
|
35
|
+
toJSON(): {
|
|
36
|
+
name: string;
|
|
37
|
+
url?: string;
|
|
38
|
+
logo?: string;
|
|
39
|
+
did: string;
|
|
40
|
+
pk: any;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { NFTIssuer as default };
|
package/lib/package.cjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
3
|
+
let _ocap_util = require("@ocap/util");
|
|
4
|
+
|
|
5
|
+
//#region src/recipient.ts
|
|
6
|
+
/**
|
|
7
|
+
* Represents an NFT recipient with wallet and metadata
|
|
8
|
+
*/
|
|
9
|
+
var NFTRecipient = class {
|
|
10
|
+
/**
|
|
11
|
+
* Creates an instance of NFTRecipient.
|
|
12
|
+
*
|
|
13
|
+
* @param params - Recipient parameters
|
|
14
|
+
* @param params.wallet - wallet object
|
|
15
|
+
* @param params.name - recipient name
|
|
16
|
+
* @param params.location - recipient location
|
|
17
|
+
*/
|
|
18
|
+
constructor({ wallet, name, location }) {
|
|
19
|
+
this.wallet = wallet;
|
|
20
|
+
this.attributes = {
|
|
21
|
+
name,
|
|
22
|
+
location
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
toJSON() {
|
|
26
|
+
return {
|
|
27
|
+
did: this.wallet.address,
|
|
28
|
+
pk: (0, _ocap_util.toBase58)(this.wallet.publicKey),
|
|
29
|
+
...this.attributes
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var recipient_default = NFTRecipient;
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
exports.default = recipient_default;
|