Last active
June 22, 2023 06:10
-
-
Save tunnckoCore/15a8864b59e44e45138bc5ae4013be94 to your computer and use it in GitHub Desktop.
ORD-721 protocol - TypeScript types, Zod Schemas, zod inferred typescript types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type ORD721RoyaltyType = { | |
address: string; | |
amount: number; | |
token: string; | |
type?: string; | |
}; | |
export type ORD721RoyaltyManifestType = { | |
protocol: { name: "ORD721"; version: string; type: "royalty" }; | |
royalty: ORD721RoyaltyType; | |
}; | |
export type ORD721FundsType = { | |
address: string; | |
amount: number; | |
token: string; | |
}; | |
export type ORD721FundsManifestType = { | |
protocol: { name: "ORD721"; version: string; type: "funds" }; | |
funds: ORD721FundsType; | |
}; | |
export type ORD721TraitsType = Record<string, any>; | |
export type ORD721TraitsManifestType = { | |
protocol: { name: "ORD721"; version: string; type: "traits" }; | |
traits: ORD721TraitsType; | |
}; | |
export type ORD721CollectionManifestType = { | |
protocol: { name: "ORD721"; version: string; type: "collection" }; | |
collection: { | |
name: string; | |
symbol: string; | |
description: string; | |
creatorAddress: string; | |
creatorPublicKey: string; | |
creatorSignature: string; | |
funds: number | string | ORD721FundsType; | |
maxSupply: number; | |
maxPerAddress: number; | |
maxBlockHeight?: number; | |
royalty?: number | string | ORD721RoyaltyType; | |
twitter?: string; | |
discord?: string; | |
website?: string; | |
}; | |
digest: string; | |
}; | |
export type ORD721TokenManifestType = { | |
protocol: { name: "ORD721"; version: string; type: "token" }; | |
token: { | |
id: number; | |
uri: string; | |
inscriberAddress: string; | |
inscriberPublicKey?: string; | |
inscriberSignature: string; | |
traits?: string | ORD721TraitsType; | |
attributes?: unknown | { [key: string]: any }[]; | |
}; | |
collectionDigest: string; | |
collectionInscriptionId: string; | |
digest: string; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
ORD721RoyaltyTypeSchema, | |
ORD721RoyaltyManifestTypeSchema, | |
ORD721FundsTypeSchema, | |
ORD721FundsManifestTypeSchema, | |
ORD721TraitsTypeSchema, | |
ORD721TraitsManifestTypeSchema, | |
ORD721CollectionManifestTypeSchema, | |
ORD721TokenManifestTypeSchema, | |
} from "./zod-schemas.ts"; | |
export type ORD721RoyaltyType = z.infer<typeof ORD721RoyaltyTypeSchema>; | |
export type ORD721RoyaltyManifestType = z.infer< | |
typeof ORD721RoyaltyManifestTypeSchema | |
>; | |
export type ORD721FundsType = z.infer<typeof ORD721FundsTypeSchema>; | |
export type ORD721FundsManifestType = z.infer< | |
typeof ORD721FundsManifestTypeSchema | |
>; | |
export type ORD721TraitsType = z.infer<typeof ORD721TraitsTypeSchema>; | |
export type ORD721TraitsManifestType = z.infer< | |
typeof ORD721TraitsManifestTypeSchema | |
>; | |
export type ORD721CollectionManifestType = z.infer< | |
typeof ORD721CollectionManifestTypeSchema | |
>; | |
export type ORD721TokenManifestType = z.infer< | |
typeof ORD721TokenManifestTypeSchema | |
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { z } from "npm:zod"; | |
export const protocolSchema = z | |
.object({ | |
name: z.literal("ORD721"), | |
version: z.literal("1.0"), | |
type: z.enum([ | |
"collection", | |
"token", | |
"traits", | |
"royalty", | |
"funds", | |
"tokens", | |
]), | |
}) | |
.strict(); | |
export const ORD721RoyaltyTypeSchema = z.object({ | |
address: z.string(), | |
amount: z.number(), | |
token: z.string(), | |
type: z.string().optional(), | |
}); | |
export const ORD721RoyaltyManifestTypeSchema = z.object({ | |
protocol: protocolSchema, | |
royalty: ORD721RoyaltyTypeSchema, | |
}); | |
export const ORD721FundsTypeSchema = z.object({ | |
address: z.string(), | |
amount: z.number(), | |
token: z.string(), | |
}); | |
export const ORD721FundsManifestTypeSchema = z.object({ | |
protocol: protocolSchema, | |
funds: ORD721FundsTypeSchema, | |
}); | |
export const ORD721TraitsTypeSchema = z.record(z.any()); | |
export const ORD721TraitsManifestTypeSchema = z.object({ | |
protocol: protocolSchema, | |
traits: ORD721TraitsTypeSchema, | |
}); | |
export const ORD721CollectionManifestTypeSchema = z.object({ | |
protocol: protocolSchema, | |
collection: z.object({ | |
name: z.string().min(4).max(32), | |
symbol: z.string().min(3).max(6), | |
description: z.string().min(10).max(256), | |
creatorAddress: z.string().min(40).max(70).startsWith("bc1", { | |
message: "Address must be a `bc1` bitcoin address", | |
}), | |
creatorPublicKey: z.string().min(40), | |
creatorSignature: z.string().min(40), | |
funds: z.union([ | |
z.number().int().nonnegative(), | |
z.string().min(40), | |
ORD721FundsTypeSchema, | |
]), | |
maxSupply: z.number().int().positive(), | |
maxPerAddress: z.number().int().positive().default(1), | |
maxBlockHeight: z.number().int().positive().optional(), | |
royalty: z | |
.union([ | |
z.number().int().nonnegative(), | |
z.string(), | |
ORD721RoyaltyTypeSchema, | |
]) | |
.optional(), | |
twitter: z | |
.string() | |
.startsWith("https://twitter.com", { | |
message: "Must provide Twitter URL", | |
}) | |
.optional(), | |
discord: z | |
.string() | |
.startsWith("https://discord", { message: "Must provide Discord URL" }) | |
.optional(), | |
website: z | |
.string() | |
.startsWith("https://", { message: "Must provide HTTPS URL" }) | |
.optional(), | |
}), | |
digest: z.string().min(40), | |
}); | |
export const tokenSchema = z | |
.object({ | |
id: z.number().int().nonnegative(), | |
uri: z.string().refine((x: string) => /data:|https?:|ipfs:/.test(x)), | |
inscriberAddress: z.string().min(40).max(70).startsWith("bc1p", { | |
message: "Address must be a `bc1p` taproot bitcoin address", | |
}), | |
inscriberPublicKey: z.string().min(40).optional(), | |
inscriberSignature: z.string().min(40), | |
traits: z.union([z.string().min(40), ORD721TraitsTypeSchema]).optional(), | |
attributes: z.union([z.unknown(), z.array(z.record(z.any()))]).optional(), | |
}) | |
.passthrough(); | |
export const ORD721TokenManifestTypeSchema = z.object({ | |
protocol: protocolSchema, | |
token: tokenSchema, | |
collectionDigest: z.string().min(40), | |
collectionInscriptionId: z.string().min(40), | |
digest: z.string().min(40), | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment