Skip to content

Commit

Permalink
Merge pull request #118 from storyprotocol/fix/add-off-chain-data-to-…
Browse files Browse the repository at this point in the history
…license-terms

fix: Update `licenseTermsData` to Include Off-Chain Data
  • Loading branch information
SoYoung210 authored Jan 31, 2025
2 parents f533a3f + 0f0e8d1 commit 10ce536
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/storykit/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@storyprotocol/storykit",
"author": "storyprotocol engineering <[email protected]>",
"version": "0.2.8",
"version": "0.2.9",
"type": "module",
"exports": {
".": {
Expand Down
1 change: 0 additions & 1 deletion packages/storykit/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,5 @@ export async function listResource<T>(

export async function getMetadataFromIpfs(ipfsUrl: string) {
const metadata = await fetch(ipfsUrl).then((res) => res.json())
console.log("@@ metadata", metadata)
return metadata
}
28 changes: 27 additions & 1 deletion packages/storykit/src/providers/IpProvider/IpProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Address, Hash } from "viem"

import { getMetadataFromIpfs, getResource, listResource } from "../../lib/api"
import { getNFTByTokenId } from "../../lib/simplehash"
import { convertIpfsUriToUrl } from "../../lib/utils"
import { RESOURCE_TYPE } from "../../types/api"
import {
Asset,
Expand Down Expand Up @@ -245,14 +246,39 @@ export const IpProvider = ({
)
const results = await Promise.all(requests)

return results
const termsDetail = results
.filter((value) => !!value)
.map((result) => {
return {
...result.data,
licenseTerms: convertLicenseTermObject(result.data.licenseTerms),
}
})

const offChainUri = termsDetail.map((detail) => detail.terms.uri)
const offChainData = await Promise.all(
offChainUri.map(async (uri) => {
try {
if (uri === "") {
return
}
const ipfsData = await getMetadataFromIpfs(convertIpfsUriToUrl(uri))
return ipfsData
} catch (error) {
return
}
})
)

return termsDetail.map((termDetail, index) => {
return {
...termDetail,
terms: {
...termDetail.terms,
offChainData: offChainData[index],
},
}
})
}

const {
Expand Down
7 changes: 7 additions & 0 deletions packages/storykit/src/types/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export type PILTerms = {
derivativesReciprocal: boolean
derivativesRevenueCelling: number
expiration: string
// @deprecated, use uri instead
uRI: string
uri?: string
}

export type IPLicenseTerms = {
Expand Down Expand Up @@ -109,13 +111,18 @@ export interface Trait {
max_value?: number
}

export interface LicenseOffChainData {
aiLearningModels?: boolean
}
export type PILTermsWithOffChainData = PILTerms & LicenseOffChainData
export type LicenseTerms = {
id: string
// json: string
licenseTerms: Trait[]
licenseTemplate: Address
blockNumber: string
blockTime: string
terms: PILTermsWithOffChainData
}

export type LicenseToken = {
Expand Down

0 comments on commit 10ce536

Please sign in to comment.