diff --git a/components/IscnUploadForm.vue b/components/IscnUploadForm.vue index 306737dd..368e7556 100644 --- a/components/IscnUploadForm.vue +++ b/components/IscnUploadForm.vue @@ -262,6 +262,7 @@ import { ISCNRecordWithID } from '~/utils/cosmos/iscn/iscn.type' const iscnModule = namespace('iscn') const walletModule = namespace('wallet') +const bookApiModule = namespace('book-api') type UploadStatus = '' | 'loading' | 'signing' | 'uploading'; const MODE = { @@ -286,6 +287,7 @@ export default class IscnUploadForm extends Vue { @walletModule.Getter('getSigner') signer!: OfflineSigner | null @walletModule.Action('initIfNecessary') initIfNecessary!: () => Promise @walletModule.Getter('getWalletAddress') address!: string + @bookApiModule.Getter('getToken') getToken!: () => string isImage: boolean = false ipfsURL: string = '' @@ -848,6 +850,7 @@ export default class IscnUploadForm extends Vue { ipfsHash: tempRecord.ipfsHash, fileType: tempRecord.fileType as string, txHash: tempRecord.transactionHash, + token: this.getToken(), }); if (arweaveId) { const uploadedData = this.sentArweaveTransactionInfo.get(record.ipfsHash) || {}; @@ -881,6 +884,7 @@ export default class IscnUploadForm extends Vue { ipfsHash: file.ipfsHash, fileType: file.fileType, txHash, + token: this.getToken(), }) } diff --git a/constant/index.ts b/constant/index.ts index e3fdf8c4..57503cfc 100644 --- a/constant/index.ts +++ b/constant/index.ts @@ -114,6 +114,8 @@ export const NFT_BOOK_PRESS_URL = IS_TESTNET ? 'https://likecoin-nft-book-press- export const SIGN_AUTHORIZATION_PERMISSIONS = [ 'profile', + 'read:iscn', + 'write:iscn', 'read:nftbook', 'write:nftbook', 'read:nftcollection', diff --git a/pages/nft/iscn/_iscnId.vue b/pages/nft/iscn/_iscnId.vue index 414d4acc..ecaddb5d 100644 --- a/pages/nft/iscn/_iscnId.vue +++ b/pages/nft/iscn/_iscnId.vue @@ -151,6 +151,7 @@ import { estimateBundlrFilePrice, uploadSingleFileToBundlr } from '~/utils/arwea const iscnModule = namespace('iscn') const walletModule = namespace('wallet') +const bookApiModule = namespace('book-api') export enum ErrorType { INSUFFICIENT_BALANCE = 'INSUFFICIENT_BALANCE', @@ -226,6 +227,8 @@ export default class NFTMintPage extends Vue { @walletModule.Getter('getWalletAddress') address!: string @walletModule.Getter('getSigner') signer!: OfflineSigner | null + @bookApiModule.Getter('getToken') getToken!: () => string + platform = this.$route.query.platform as string || '' isNewsPress = !!this.$route.query.news_press && this.$route.query.news_press !== '0' @@ -818,6 +821,7 @@ export default class NFTMintPage extends Vue { ipfsHash: await this.getOgImageIpfsHash(), fileType: this.ogImageBlob.type, txHash: this.ogImageArweaveFeeTxHash, + token: this.getToken(), }); logTrackerEvent(this, 'IscnMintNFT', 'SubmitToArweaveSuccess', arweaveId as string, 1); this.ogImageArweaveId = arweaveId as string diff --git a/utils/arweave/v2.ts b/utils/arweave/v2.ts index c469081b..5c30e8dd 100644 --- a/utils/arweave/v2.ts +++ b/utils/arweave/v2.ts @@ -13,6 +13,7 @@ class Provider { fileSize = 0 ipfsHash = '' txHash = '' + token = '' constructor({ publicKey, @@ -53,6 +54,10 @@ class Provider { return this.pubKey } + getArweaveRegisterApiToken() { + return this.token + } + getSigner = () => ({ getAddress: () => this.pubKey?.toString(), _signTypedData: async ( @@ -69,7 +74,8 @@ class Provider { ipfsHash: this.ipfsHash, txHash: this.txHash, }) - const { signature } = await res.data + const { signature, token } = await res.data + this.token = token; const bSig = Buffer.from(signature, 'base64') // pad & convert so it's in the format the signer expects to have to convert from. const pad = Buffer.concat([ @@ -123,6 +129,7 @@ async function getBundler({ 'matic', p, ) + bundlr.getArweaveApiToken = p.getArweaveRegisterApiToken.bind(p) await bundlr.ready() return bundlr } @@ -148,7 +155,8 @@ export async function uploadSingleFileToBundlr( fileSize, ipfsHash, txHash, - }: { fileSize: number; fileType?: string, ipfsHash: string; txHash: string }, + token, + }: { fileSize: number; fileType?: string, ipfsHash: string; txHash: string, token: string }, ) { const bundler = await getBundler({ fileSize, ipfsHash, txHash }) const tags = [ @@ -160,6 +168,7 @@ export async function uploadSingleFileToBundlr( ]; if (fileType) tags.push({ name: 'Content-Type', value: fileType }) const response = await bundler.upload(file, { tags }) + const arweaveAPIToken = bundler.getArweaveApiToken(); const arweaveId = response.id; if (arweaveId) { await axios.post(API_POST_ARWEAVE_V2_REGISTER, { @@ -167,6 +176,9 @@ export async function uploadSingleFileToBundlr( ipfsHash, txHash, arweaveId, + },{ + headers: { Authorization: token ? `Bearer ${token}` : '' }, + params: { token: arweaveAPIToken }, }); } return arweaveId;