Skip to content

example repo to unlock the music stored onchain for anotherblock

Notifications You must be signed in to change notification settings

Anotherblock/digital-vinyl-decrypt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

decrypt music

this is a guide to play your music that is encrypted onchain.

requirements

  • bun runtime
  • anotherblock music nft
  • wallet private key

steps

  1. start by creating a new project (bun init etc)
  2. install the following packages:
bun add viem siwe @lit-protocol/lit-node-client
  1. create a .env and put your private key in the PRIVATE_KEY
  2. find the url to the content metadata. you'll find this in the nft metadata in the content property. e.g ich r u - boys noize: https://arweave.net/vO3M5ALVROim8M-yRlQgt7jb7b7rc1c5mHYkigrg-dw
  3. download this file to content-metadata.json in the project directory.
curl -o content-metadata.json https://arweave.net/vO3M5ALVROim8M-yRlQgt7jb7b7rc1c5mHYkigrg-dw -L
  1. now, create a new file called decrypt.ts with the following contents:
import { decryptFile, LitNodeClient } from '@lit-protocol/lit-node-client';
import { SiweMessage } from 'siwe';
import { createWalletClient, Hex, http } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { base } from 'viem/chains';

import contentMetadata from './content-metadata.json';

const litClient = new LitNodeClient({});

const account = privateKeyToAccount(process.env.PRIVATE_KEY as Hex);

const walletClient = createWalletClient({
  account,
  transport: http(base.rpcUrls.default.http[0])
});

const { chainId, domain, statement, version } = contentMetadata.config;

const siweMessage = new SiweMessage({
  domain,
  address: account.address,
  statement,
  uri: `https://${domain}`,
  chainId,
  version
});

const message = siweMessage.prepareMessage();

const signature = await walletClient.signMessage({ message });

const authSig = {
  sig: signature,
  derivedVia: 'web3.eth.personal.sign',
  signedMessage: message,
  address: account.address
};

await litClient.connect();

const encryptionKey = await litClient.getEncryptionKey({
  toDecrypt: contentMetadata.encryptedSymmetricKey,
  authSig,
  chain: contentMetadata.config.chain,
  accessControlConditions: contentMetadata.acc
});

const fileResponse = await fetch(contentMetadata.fileUrl);

const file = new Blob([await fileResponse.arrayBuffer()]);

const decryptedFile = await decryptFile({
  file,
  symmetricKey: encryptionKey
});

Bun.write(`music.mp3`, Buffer.from(decryptedFile));
  1. run the file with bun run decrypt.ts
  2. enjoy the music in music.mp3

About

example repo to unlock the music stored onchain for anotherblock

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published