@zoralabs/protocol-sdk 0.7.0 → 0.7.2-ALLOWLIST.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/CHANGELOG.md +12 -0
- package/dist/allow-list/allow-list-client.d.ts +25 -0
- package/dist/allow-list/allow-list-client.d.ts.map +1 -0
- package/dist/allow-list/types.d.ts +14 -0
- package/dist/allow-list/types.d.ts.map +1 -0
- package/dist/apis/generated/allow-list-api-types.d.ts +288 -0
- package/dist/apis/generated/allow-list-api-types.d.ts.map +1 -0
- package/dist/apis/http-api-base.d.ts.map +1 -1
- package/dist/create/1155-create-helper.d.ts +1 -0
- package/dist/create/1155-create-helper.d.ts.map +1 -1
- package/dist/create/token-setup.d.ts +3 -4
- package/dist/create/token-setup.d.ts.map +1 -1
- package/dist/create/types.d.ts +24 -4
- package/dist/create/types.d.ts.map +1 -1
- package/dist/index.cjs +1388 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1382 -51
- package/dist/index.js.map +1 -1
- package/dist/ipfs/arweave.d.ts +3 -0
- package/dist/ipfs/arweave.d.ts.map +1 -0
- package/dist/ipfs/gateway.d.ts +4 -0
- package/dist/ipfs/gateway.d.ts.map +1 -0
- package/dist/ipfs/index.d.ts +4 -0
- package/dist/ipfs/index.d.ts.map +1 -0
- package/dist/ipfs/ipfs.d.ts +5 -0
- package/dist/ipfs/ipfs.d.ts.map +1 -0
- package/dist/ipfs/mimeTypes.d.ts +25 -0
- package/dist/ipfs/mimeTypes.d.ts.map +1 -0
- package/dist/ipfs/text-metadata.d.ts +5 -0
- package/dist/ipfs/text-metadata.d.ts.map +1 -0
- package/dist/ipfs/token-metadata.d.ts +14 -0
- package/dist/ipfs/token-metadata.d.ts.map +1 -0
- package/dist/ipfs/types.d.ts +49 -0
- package/dist/ipfs/types.d.ts.map +1 -0
- package/dist/mint/mint-queries.d.ts +3 -1
- package/dist/mint/mint-queries.d.ts.map +1 -1
- package/dist/mint/mint-transactions.d.ts +5 -3
- package/dist/mint/mint-transactions.d.ts.map +1 -1
- package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
- package/dist/mint/subgraph-queries.d.ts +27 -13
- package/dist/mint/subgraph-queries.d.ts.map +1 -1
- package/dist/mint/types.d.ts +22 -11
- package/dist/mint/types.d.ts.map +1 -1
- package/dist/premint/premint-client.d.ts +2 -1
- package/dist/premint/premint-client.d.ts.map +1 -1
- package/package.json +3 -1
- package/src/allow-list/allow-list-client.ts +102 -0
- package/src/allow-list/types.ts +15 -0
- package/src/apis/generated/allow-list-api-types.ts +288 -0
- package/src/apis/http-api-base.ts +12 -0
- package/src/create/1155-create-helper.ts +17 -0
- package/src/create/token-setup.ts +116 -19
- package/src/create/types.ts +32 -4
- package/src/index.ts +6 -0
- package/src/ipfs/arweave.ts +5 -0
- package/src/ipfs/gateway.ts +48 -0
- package/src/ipfs/index.ts +7 -0
- package/src/ipfs/ipfs.ts +82 -0
- package/src/ipfs/mimeTypes.ts +141 -0
- package/src/ipfs/text-metadata.ts +128 -0
- package/src/ipfs/token-metadata.ts +99 -0
- package/src/ipfs/types.ts +54 -0
- package/src/mint/mint-queries.ts +6 -0
- package/src/mint/mint-transactions.ts +72 -6
- package/src/mint/subgraph-mint-getter.ts +12 -3
- package/src/mint/subgraph-queries.ts +39 -17
- package/src/mint/types.ts +38 -12
- package/src/premint/premint-client.ts +9 -1
- package/yarn-error.log +8602 -0
- package/.turbo/turbo-build.log +0 -15
- package/src/create/1155-create-helper.test.ts +0 -325
- package/src/mint/mint-client.test.ts +0 -263
- package/src/mints/mints-contracts.test.ts +0 -529
- package/src/mints/mints-eth-unwrapper-and-caller.test.ts +0 -467
- package/src/mints/mints-queries.test.ts +0 -105
- package/src/premint/premint-client.test.ts +0 -290
- package/src/premint/preminter.test.ts +0 -866
- package/test-integration/setup-test-contracts.ts +0 -96
- package/tsconfig.build.json +0 -10
- package/tsup.config.ts +0 -12
package/src/ipfs/ipfs.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { CID } from "multiformats/cid";
|
|
2
|
+
|
|
3
|
+
export type IPFSUrl = `ipfs://${string}`;
|
|
4
|
+
|
|
5
|
+
export function isCID(str: string | null | undefined): boolean {
|
|
6
|
+
if (!str) return false;
|
|
7
|
+
|
|
8
|
+
try {
|
|
9
|
+
CID.parse(str);
|
|
10
|
+
return true;
|
|
11
|
+
} catch (e) {
|
|
12
|
+
if (/^(bafy|Qm)/.test(str)) return true;
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function normalizeIPFSUrl(
|
|
18
|
+
url: string | null | undefined,
|
|
19
|
+
): IPFSUrl | null {
|
|
20
|
+
if (!url || typeof url !== "string") return null;
|
|
21
|
+
|
|
22
|
+
// Handle urls wrapped in quotes
|
|
23
|
+
url = url.replace(/"/g, "");
|
|
24
|
+
|
|
25
|
+
// Check if already a normalized IPFS url
|
|
26
|
+
if (isNormalizedIPFSURL(url)) return url as IPFSUrl;
|
|
27
|
+
|
|
28
|
+
// Check if url is a CID string
|
|
29
|
+
if (isCID(url)) return `ipfs://${url}`;
|
|
30
|
+
|
|
31
|
+
// If url is not either an ipfs gateway or protocol url
|
|
32
|
+
if (!isIPFSUrl(url)) return null;
|
|
33
|
+
|
|
34
|
+
// If url is already a gateway url, parse and normalize
|
|
35
|
+
if (isGatewayIPFSUrl(url)) {
|
|
36
|
+
// Replace leading double-slashes and parse URL
|
|
37
|
+
const parsed = new URL(url.replace(/^\/\//, "http://"));
|
|
38
|
+
// Remove IPFS from the URL
|
|
39
|
+
// http://gateway/ipfs/<CID>?x=y#z -> http://gateway/<CID>?x=y#z
|
|
40
|
+
parsed.pathname = parsed.pathname.replace(/^\/ipfs\//, "");
|
|
41
|
+
// Remove the protocol and host from the URL
|
|
42
|
+
// http://gateway/<CID>?x=y#z -> <CID>?x=y#z
|
|
43
|
+
const cid = parsed
|
|
44
|
+
.toString()
|
|
45
|
+
.replace(`${parsed.protocol}//${parsed.host}/`, "");
|
|
46
|
+
// Prepend ipfs protocol
|
|
47
|
+
return `ipfs://${cid}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function isNormalizedIPFSURL(url: string | null | undefined): boolean {
|
|
54
|
+
return url && typeof url === "string" ? url.startsWith("ipfs://") : false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function isGatewayIPFSUrl(url: string | null | undefined): boolean {
|
|
58
|
+
if (url && typeof url === "string") {
|
|
59
|
+
try {
|
|
60
|
+
const parsed = new URL(url.replace(/^"|'(.*)"|'$/, "$1"));
|
|
61
|
+
return (
|
|
62
|
+
!isNormalizedIPFSURL(url) &&
|
|
63
|
+
parsed &&
|
|
64
|
+
parsed.pathname.startsWith("/ipfs/")
|
|
65
|
+
);
|
|
66
|
+
} catch {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function isIPFSUrl(url: string | null | undefined): boolean {
|
|
75
|
+
return url ? isNormalizedIPFSURL(url) || isGatewayIPFSUrl(url) : false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function isNormalizeableIPFSUrl(
|
|
79
|
+
url: string | null | undefined,
|
|
80
|
+
): boolean {
|
|
81
|
+
return url ? isIPFSUrl(url) || isCID(url) : false;
|
|
82
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// text
|
|
2
|
+
const HTML = "text/html";
|
|
3
|
+
const MARKDOWN = "text/markdown";
|
|
4
|
+
const MARKDOWN_UTF8 = "text/markdown; charset=utf-8";
|
|
5
|
+
const TEXT_PLAIN_UTF8 = "text/plain; charset=utf-8";
|
|
6
|
+
export const TEXT_PLAIN = "text/plain";
|
|
7
|
+
const CSV = "text/csv";
|
|
8
|
+
const NUMBERS = ".numbers";
|
|
9
|
+
const EXCEL = ".xlsx";
|
|
10
|
+
const PDF = "application/pdf";
|
|
11
|
+
|
|
12
|
+
// image
|
|
13
|
+
const JPG = "image/jpg";
|
|
14
|
+
const JPEG = "image/jpeg";
|
|
15
|
+
const PNG = "image/png";
|
|
16
|
+
const WEBP = "image/webp";
|
|
17
|
+
const SVG = "image/svg+xml";
|
|
18
|
+
const TIFF = "image/tiff";
|
|
19
|
+
const GIF = "image/gif";
|
|
20
|
+
|
|
21
|
+
export const isImage = (mimeType: string | null | undefined) => {
|
|
22
|
+
if (!mimeType) return false;
|
|
23
|
+
return [JPG, JPEG, PNG, WEBP, SVG, TIFF, GIF].includes(mimeType);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export enum MediaType {
|
|
27
|
+
CSV = "CSV",
|
|
28
|
+
NUMBERS = "NUMBERS",
|
|
29
|
+
EXCEL = "EXCEL",
|
|
30
|
+
IMAGE = "IMAGE",
|
|
31
|
+
VIDEO = "VIDEO",
|
|
32
|
+
AUDIO = "AUDIO",
|
|
33
|
+
TIFF = "TIFF",
|
|
34
|
+
TEXT = "TEXT",
|
|
35
|
+
PDF = "PDF",
|
|
36
|
+
MODEL = "MODEL",
|
|
37
|
+
HTML = "HTML",
|
|
38
|
+
ZIP = "ZIP",
|
|
39
|
+
UNKNOWN = "UNKNOWN",
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const DEFAULT_THUMBNAIL_CID_HASHES: { [key: string]: string } = {
|
|
43
|
+
[MediaType.AUDIO]:
|
|
44
|
+
"bafkreidir5laqi26ta6ivnpe2zpekgrfcyi4tb5x6vhwmwnledmzxshfb4",
|
|
45
|
+
[MediaType.VIDEO]:
|
|
46
|
+
"bafkreifm4edadl3j5luoyvw4p6elxeqd77la7bulee6vhq5gq4chfk32mu",
|
|
47
|
+
[MediaType.HTML]:
|
|
48
|
+
"bafkreifgvi6xfwqy2l6g45csyokejpaib52ee7zrw6etrxl2tas4xkkclq",
|
|
49
|
+
[MediaType.ZIP]:
|
|
50
|
+
"bafkreihe5rr5jbkwzegisjlhxbb7jw22xw5oilfmgd2re6tz6buo4pasdq", // assuming all zip files are html directories
|
|
51
|
+
[MediaType.TEXT]:
|
|
52
|
+
"bafkreiaez25nfgggzrnza2loxf6xueb2esm44pnyjyulwoslnipowrf56q",
|
|
53
|
+
default: "bafkreihcoahllisbpb4eeypdwtm7go5uh275wxd7wf2tantpxlpjhviok4",
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// video
|
|
57
|
+
const MP4 = "video/mp4";
|
|
58
|
+
const QUICKTIME = "video/quicktime";
|
|
59
|
+
const M4V = "video/x-m4v";
|
|
60
|
+
const WEBM = "video/webm";
|
|
61
|
+
|
|
62
|
+
// audio
|
|
63
|
+
const M4A = "audio/x-m4a";
|
|
64
|
+
const MPEG = "audio/mpeg";
|
|
65
|
+
const MP3 = "audio/mp3";
|
|
66
|
+
const WAV = "audio/wav";
|
|
67
|
+
const VND_WAV = "audio/vnd.wav";
|
|
68
|
+
const VND_WAVE = "audio/vnd.wave";
|
|
69
|
+
const WAVE = "audio/wave";
|
|
70
|
+
const X_WAV = "audio/x-wav";
|
|
71
|
+
const AIFF = "audio/aiff";
|
|
72
|
+
|
|
73
|
+
// 3D
|
|
74
|
+
const GLTF = "model/gltf+json";
|
|
75
|
+
const GLB = "model/gltf-binary";
|
|
76
|
+
// File extensions, as some files return '' as the mimetype
|
|
77
|
+
const GLTF_EXT = ".gltf";
|
|
78
|
+
const GLB_EXT = ".glb";
|
|
79
|
+
|
|
80
|
+
// application
|
|
81
|
+
export const JSON_MIME_TYPE = "application/json";
|
|
82
|
+
const ZIP = "application/zip";
|
|
83
|
+
|
|
84
|
+
const mimeToMediaType = {
|
|
85
|
+
[HTML]: MediaType.HTML,
|
|
86
|
+
[JPG]: MediaType.IMAGE,
|
|
87
|
+
[JPEG]: MediaType.IMAGE,
|
|
88
|
+
[PNG]: MediaType.IMAGE,
|
|
89
|
+
[WEBP]: MediaType.IMAGE,
|
|
90
|
+
[SVG]: MediaType.IMAGE,
|
|
91
|
+
[TIFF]: MediaType.TIFF,
|
|
92
|
+
[GIF]: MediaType.IMAGE,
|
|
93
|
+
[MP4]: MediaType.VIDEO,
|
|
94
|
+
[WEBM]: MediaType.VIDEO,
|
|
95
|
+
[QUICKTIME]: MediaType.VIDEO,
|
|
96
|
+
[M4V]: MediaType.VIDEO,
|
|
97
|
+
[MPEG]: MediaType.AUDIO,
|
|
98
|
+
[MP3]: MediaType.AUDIO,
|
|
99
|
+
[M4A]: MediaType.AUDIO,
|
|
100
|
+
[VND_WAV]: MediaType.AUDIO,
|
|
101
|
+
[VND_WAVE]: MediaType.AUDIO,
|
|
102
|
+
[WAV]: MediaType.AUDIO,
|
|
103
|
+
[WAVE]: MediaType.AUDIO,
|
|
104
|
+
[X_WAV]: MediaType.AUDIO,
|
|
105
|
+
[AIFF]: MediaType.AUDIO,
|
|
106
|
+
[TEXT_PLAIN]: MediaType.TEXT,
|
|
107
|
+
[TEXT_PLAIN_UTF8]: MediaType.TEXT,
|
|
108
|
+
[MARKDOWN]: MediaType.TEXT,
|
|
109
|
+
[MARKDOWN_UTF8]: MediaType.TEXT,
|
|
110
|
+
[CSV]: MediaType.CSV,
|
|
111
|
+
[NUMBERS]: MediaType.NUMBERS,
|
|
112
|
+
[EXCEL]: MediaType.EXCEL,
|
|
113
|
+
[PDF]: MediaType.PDF,
|
|
114
|
+
[ZIP]: MediaType.ZIP,
|
|
115
|
+
[GLTF]: MediaType.MODEL,
|
|
116
|
+
[GLTF_EXT]: MediaType.MODEL,
|
|
117
|
+
[GLB]: MediaType.MODEL,
|
|
118
|
+
// GLTF returns 'application/json' as the mimetype,
|
|
119
|
+
// and as the only JSON-encoded media we currently support,
|
|
120
|
+
// we assume that if the mimetype is JSON, it's a GLTF
|
|
121
|
+
[JSON_MIME_TYPE]: MediaType.MODEL,
|
|
122
|
+
[GLB_EXT]: MediaType.MODEL,
|
|
123
|
+
} as const;
|
|
124
|
+
|
|
125
|
+
/** Return a MediaType for the given mime type. If mime type is unknown you can provide a filename as a fallback, where the type will be guessed based on extension. */
|
|
126
|
+
export function mimeTypeToMedia(mimeType?: string | null) {
|
|
127
|
+
if (!mimeType) return MediaType.UNKNOWN;
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
mimeToMediaType[mimeType as keyof typeof mimeToMediaType] ||
|
|
131
|
+
MediaType.UNKNOWN
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export async function getMimeType(uri?: string) {
|
|
136
|
+
if (!uri) return uri;
|
|
137
|
+
|
|
138
|
+
const res = await fetch(uri, { method: "HEAD" });
|
|
139
|
+
let mimeType = res.headers.get("content-type");
|
|
140
|
+
return mimeType;
|
|
141
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { TextMetadataFiles } from "./types";
|
|
2
|
+
|
|
3
|
+
const CHAR_LIMIT = 1111;
|
|
4
|
+
|
|
5
|
+
const wrapText = ({
|
|
6
|
+
ctx,
|
|
7
|
+
text,
|
|
8
|
+
x,
|
|
9
|
+
y,
|
|
10
|
+
maxWidth,
|
|
11
|
+
lineHeight,
|
|
12
|
+
}: {
|
|
13
|
+
ctx: CanvasRenderingContext2D;
|
|
14
|
+
text: string;
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
maxWidth: number;
|
|
18
|
+
lineHeight: number;
|
|
19
|
+
}) => {
|
|
20
|
+
// Split text into words
|
|
21
|
+
let words = text.replaceAll("\n", " \n ").split(/ +/);
|
|
22
|
+
let line = ""; // This will store the text of the current line
|
|
23
|
+
let testLine = ""; // This will store the text when we add a word, to test if it's too long
|
|
24
|
+
let lineArray = []; // This is an array of lines, which the function will return
|
|
25
|
+
|
|
26
|
+
for (var n = 0; n < words.length; n++) {
|
|
27
|
+
// Measure text sizing
|
|
28
|
+
testLine += `${words[n]} `;
|
|
29
|
+
let metrics = ctx.measureText(testLine);
|
|
30
|
+
let testWidth = metrics.width;
|
|
31
|
+
// If the width of this test line is more than the max width
|
|
32
|
+
if (words[n]?.includes("\n") || (testWidth > maxWidth && n > 0)) {
|
|
33
|
+
// Then the line is finished, push the current line into "lineArray"
|
|
34
|
+
lineArray.push({ text: line, x, y });
|
|
35
|
+
// Start a new line
|
|
36
|
+
y += lineHeight;
|
|
37
|
+
// Update line and test line to use this word as the first word on the next line
|
|
38
|
+
// If it's a newline, then don't add a space
|
|
39
|
+
if (words[n]?.includes("\n")) {
|
|
40
|
+
line = ``;
|
|
41
|
+
testLine = ``;
|
|
42
|
+
} else {
|
|
43
|
+
line = `${words[n]} `;
|
|
44
|
+
testLine = `${words[n]} `;
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
// Test line is less than the max width, add the word to the current line
|
|
48
|
+
line += `${words[n]} `;
|
|
49
|
+
}
|
|
50
|
+
// Handle a single line...
|
|
51
|
+
if (n === words.length - 1) {
|
|
52
|
+
lineArray.push({ text: line, x, y });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return lineArray;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
async function generateTextPreview(text: string): Promise<File> {
|
|
59
|
+
// Trim the text to a reasonable max length. Prevent crashes if the user pastes a gigantic string
|
|
60
|
+
const trimmedText = text.trim().slice(0, CHAR_LIMIT);
|
|
61
|
+
|
|
62
|
+
const [width, height] = [500, 500];
|
|
63
|
+
const padding = 20;
|
|
64
|
+
const dpr = 2;
|
|
65
|
+
|
|
66
|
+
const fontFamily = "Inter";
|
|
67
|
+
const [fontSize, lineHeight] = [16, 24];
|
|
68
|
+
const [textColor, backgroundColor] = ["black", "white"];
|
|
69
|
+
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
const canvas = document.createElement("canvas");
|
|
72
|
+
canvas.width = width * dpr;
|
|
73
|
+
canvas.height = height * dpr;
|
|
74
|
+
const ctx = canvas.getContext("2d");
|
|
75
|
+
if (!ctx) {
|
|
76
|
+
return reject(new Error("Could not create canvas context"));
|
|
77
|
+
}
|
|
78
|
+
ctx.fillStyle = backgroundColor;
|
|
79
|
+
ctx.fillRect(0, 0, width * dpr, width * dpr);
|
|
80
|
+
ctx.fillStyle = textColor;
|
|
81
|
+
ctx.font = `${fontSize * dpr}px ${fontFamily}`;
|
|
82
|
+
const wrapped = wrapText({
|
|
83
|
+
ctx,
|
|
84
|
+
text: trimmedText,
|
|
85
|
+
x: padding * dpr,
|
|
86
|
+
y: fontSize * dpr + padding * dpr,
|
|
87
|
+
maxWidth: width * dpr - padding * 2 * dpr,
|
|
88
|
+
lineHeight: lineHeight * dpr,
|
|
89
|
+
});
|
|
90
|
+
wrapped.forEach((line) => ctx.fillText(line.text, line.x, line.y));
|
|
91
|
+
canvas.toBlob((blob) => {
|
|
92
|
+
if (!blob) {
|
|
93
|
+
return reject(new Error("Could not create blob"));
|
|
94
|
+
}
|
|
95
|
+
resolve(new File([blob], "thumbnail.png", { type: "image/png" }));
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function generateTextTitle(text: string) {
|
|
101
|
+
const firstLine = text.split("\n")[0]!;
|
|
102
|
+
const firstSentence = firstLine?.split(". ")[0]!;
|
|
103
|
+
|
|
104
|
+
if (firstSentence.length > 50) {
|
|
105
|
+
return firstSentence.slice(0, 50) + "...";
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return firstSentence;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const toTextFile = (text: string) =>
|
|
112
|
+
new File([text], "Untitled.txt", { type: "text/plain" });
|
|
113
|
+
|
|
114
|
+
/** For text nfts, this will generate files that are needed for the metadata json, including the txt.file containing the text, and a thumbnail image containing a preview of the text
|
|
115
|
+
*/
|
|
116
|
+
export async function generateTextNftMetadataFiles(
|
|
117
|
+
text: string,
|
|
118
|
+
): Promise<TextMetadataFiles> {
|
|
119
|
+
const name = generateTextTitle(text);
|
|
120
|
+
const textFile = toTextFile(text);
|
|
121
|
+
const thumbnailFile = await generateTextPreview(text);
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
name,
|
|
125
|
+
mediaUrlFile: textFile,
|
|
126
|
+
thumbnailFile,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { getFetchableUrl } from "./gateway";
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_THUMBNAIL_CID_HASHES,
|
|
4
|
+
TEXT_PLAIN,
|
|
5
|
+
getMimeType,
|
|
6
|
+
isImage,
|
|
7
|
+
mimeTypeToMedia,
|
|
8
|
+
} from "./mimeTypes";
|
|
9
|
+
import {
|
|
10
|
+
MakeMediaMetadataParams,
|
|
11
|
+
MakeTextMetadataParams,
|
|
12
|
+
TokenMetadataJson,
|
|
13
|
+
} from "./types";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Takes properties for a text based nft and formats it as proper json metadata
|
|
17
|
+
* for the token, which should be uploaded to IPFS.
|
|
18
|
+
* @param parameters - The parameters to format into metadata {@link MakeTextMetadataParams}
|
|
19
|
+
*/
|
|
20
|
+
export const makeTextTokenMetadata = (
|
|
21
|
+
parameters: MakeTextMetadataParams,
|
|
22
|
+
): TokenMetadataJson => {
|
|
23
|
+
const { name, textFileUrl, thumbnailUrl, attributes = [] } = parameters;
|
|
24
|
+
|
|
25
|
+
const content = textFileUrl
|
|
26
|
+
? {
|
|
27
|
+
mime: TEXT_PLAIN,
|
|
28
|
+
uri: textFileUrl,
|
|
29
|
+
}
|
|
30
|
+
: null;
|
|
31
|
+
|
|
32
|
+
const image = thumbnailUrl;
|
|
33
|
+
const animation_url = textFileUrl;
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
name,
|
|
37
|
+
image,
|
|
38
|
+
animation_url,
|
|
39
|
+
content,
|
|
40
|
+
attributes,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Takes properties for a media based nft (video, image, etc) and formats it as proper json metadata
|
|
46
|
+
* for the token, which should be uploaded to IPFS.
|
|
47
|
+
* @param parameters - The parameters to format into metadata {@link MakeMediaMetadataParams}
|
|
48
|
+
*/
|
|
49
|
+
export const makeMediaTokenMetadata = async ({
|
|
50
|
+
name,
|
|
51
|
+
description,
|
|
52
|
+
attributes = [],
|
|
53
|
+
mediaUrl,
|
|
54
|
+
thumbnailUrl,
|
|
55
|
+
}: MakeMediaMetadataParams): Promise<TokenMetadataJson> => {
|
|
56
|
+
const contentUrl = mediaUrl;
|
|
57
|
+
const fetchableContentUrl = getFetchableUrl(contentUrl);
|
|
58
|
+
|
|
59
|
+
if (!fetchableContentUrl)
|
|
60
|
+
throw new Error(`Content url (${contentUrl}) is not fetchable`);
|
|
61
|
+
|
|
62
|
+
const mimeType = await getMimeType(fetchableContentUrl);
|
|
63
|
+
const mediaType = mimeTypeToMedia(mimeType);
|
|
64
|
+
|
|
65
|
+
let image: string | undefined = undefined;
|
|
66
|
+
let animation_url: string | null = null;
|
|
67
|
+
|
|
68
|
+
// If the media is an image, just set the image field
|
|
69
|
+
// Otherwise we require a thumbnail, set image and animation_url
|
|
70
|
+
if (isImage(mimeType)) {
|
|
71
|
+
image = contentUrl;
|
|
72
|
+
} else {
|
|
73
|
+
image = thumbnailUrl;
|
|
74
|
+
animation_url = mediaUrl;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// If no image determined, use a fallback placeholder
|
|
78
|
+
if (!image)
|
|
79
|
+
image = `ipfs://${
|
|
80
|
+
DEFAULT_THUMBNAIL_CID_HASHES[mediaType] ||
|
|
81
|
+
DEFAULT_THUMBNAIL_CID_HASHES.default
|
|
82
|
+
}`;
|
|
83
|
+
|
|
84
|
+
const content = contentUrl
|
|
85
|
+
? {
|
|
86
|
+
mime: mimeType || "application/octet-stream",
|
|
87
|
+
uri: contentUrl,
|
|
88
|
+
}
|
|
89
|
+
: null;
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
name,
|
|
93
|
+
description,
|
|
94
|
+
image,
|
|
95
|
+
animation_url,
|
|
96
|
+
content,
|
|
97
|
+
attributes,
|
|
98
|
+
};
|
|
99
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export type CreateERC1155TokenAttributes = {
|
|
2
|
+
trait_type: string;
|
|
3
|
+
value: string;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export type ContractMetadataJson = {
|
|
7
|
+
name?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
image?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type TokenMetadataJson = {
|
|
13
|
+
name: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
/** Primary image file */
|
|
16
|
+
image?: string;
|
|
17
|
+
animation_url?: string | null;
|
|
18
|
+
content?: {
|
|
19
|
+
mime: string;
|
|
20
|
+
uri: string;
|
|
21
|
+
} | null;
|
|
22
|
+
attributes: Array<CreateERC1155TokenAttributes>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type BaseMetadataParams = {
|
|
26
|
+
/** Token name */
|
|
27
|
+
name: string;
|
|
28
|
+
/** Optional description */
|
|
29
|
+
description?: string;
|
|
30
|
+
/** Optional attributes to tag the token with */
|
|
31
|
+
attributes?: CreateERC1155TokenAttributes[];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type MakeTextMetadataParams = BaseMetadataParams & {
|
|
35
|
+
/** Ipfs url where media is hosted */
|
|
36
|
+
textFileUrl: string;
|
|
37
|
+
/** If thumbnail was generate for text file, thumbnail image url */
|
|
38
|
+
thumbnailUrl?: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export type TextMetadataFiles = {
|
|
42
|
+
name: string;
|
|
43
|
+
/** File that holds the text, and is the primary media */
|
|
44
|
+
mediaUrlFile: File;
|
|
45
|
+
/** Thumbnail image preview of the text */
|
|
46
|
+
thumbnailFile: File;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type MakeMediaMetadataParams = BaseMetadataParams & {
|
|
50
|
+
/** Ipfs url where media is hosted */
|
|
51
|
+
mediaUrl: string;
|
|
52
|
+
/** Ipfs url where thumbnail of media is hosted */
|
|
53
|
+
thumbnailUrl?: string;
|
|
54
|
+
};
|
package/src/mint/mint-queries.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
import { makeOnchainMintCall, parseMintCosts } from "./mint-transactions";
|
|
28
28
|
import { buildPremintMintCall } from "src/premint/premint-client";
|
|
29
29
|
import { IPublicClient } from "src/types";
|
|
30
|
+
import { AllowListEntry } from "src/allow-list/types";
|
|
30
31
|
|
|
31
32
|
export async function getMint({
|
|
32
33
|
params,
|
|
@@ -129,11 +130,13 @@ export async function getMintsOfContract({
|
|
|
129
130
|
|
|
130
131
|
export async function getMintCosts({
|
|
131
132
|
params,
|
|
133
|
+
allowListEntry,
|
|
132
134
|
mintGetter,
|
|
133
135
|
premintGetter,
|
|
134
136
|
publicClient,
|
|
135
137
|
}: {
|
|
136
138
|
params: GetMintCostsParameters;
|
|
139
|
+
allowListEntry?: Pick<AllowListEntry, "price">;
|
|
137
140
|
mintGetter: IOnchainMintGetter;
|
|
138
141
|
premintGetter: IPremintGetter;
|
|
139
142
|
publicClient: IPublicClient;
|
|
@@ -150,6 +153,7 @@ export async function getMintCosts({
|
|
|
150
153
|
mintFeePerQuantity: salesConfigAndTokenInfo.mintFeePerQuantity,
|
|
151
154
|
salesConfig: salesConfigAndTokenInfo.salesConfig,
|
|
152
155
|
quantityToMint: BigInt(quantityToMint),
|
|
156
|
+
allowListEntry,
|
|
153
157
|
});
|
|
154
158
|
}
|
|
155
159
|
|
|
@@ -258,6 +262,7 @@ const makeOnchainPrepareMint =
|
|
|
258
262
|
salesConfig: result.salesConfig,
|
|
259
263
|
quantityToMint: BigInt(params.quantityToMint),
|
|
260
264
|
mintFeePerQuantity: result.mintFeePerQuantity,
|
|
265
|
+
allowListEntry: params.allowListEntry,
|
|
261
266
|
}),
|
|
262
267
|
});
|
|
263
268
|
|
|
@@ -286,6 +291,7 @@ const makePremintPrepareMint =
|
|
|
286
291
|
mintFeePerQuantity: mintFee,
|
|
287
292
|
quantityToMint: BigInt(params.quantityToMint),
|
|
288
293
|
salesConfig: mintable.salesConfig,
|
|
294
|
+
allowListEntry: params.allowListEntry,
|
|
289
295
|
}),
|
|
290
296
|
});
|
|
291
297
|
|