Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Create initial pinata implementation. Pinata has different apis node/browser due to FormData #222

Draft
wants to merge 17 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.eslint.json",
"tsconfigRootDir": "./"
},
"env": { "es6": true },
"ignorePatterns": ["node_modules", "build", "coverage", "test", "jest.config.js", "tmp"],
"ignorePatterns": ["node_modules", "build", "coverage", "test", "tmp"],
"plugins": ["import", "eslint-comments"],
"extends": [
"eslint:recommended",
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/lint-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [16.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand All @@ -30,6 +30,7 @@ jobs:
restore-keys: npm-

- name: Configure
if: ${{ matrix.node-version == '16.x'}}
run: npm config set scripts-prepend-node-path auto

- name: Install
Expand All @@ -42,6 +43,10 @@ jobs:
run: npm run build

- name: Test
env:
PINATAAPIKEY: ${{ secrets.PINATAAPIKEY }}
PINATASECRETAPIKEY: ${{ secrets.PINATASECRETAPIKEY }}
PINATAJWTKEY: ${{ secrets.PINATAJWTKEY }}
run: npm run generate-types && npm run test # Types needed for tests

- name: Upload coverage to Codecov
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ jobs:
run: npm run build

- name: 🎯 Test
env:
PINATAAPIKEY: ${{ secrets.PINATAAPIKEY }}
PINATASECRETAPIKEY: ${{ secrets.PINATASECRETAPIKEY }}
PINATAJWTKEY: ${{ secrets.PINATAJWTKEY }}
run: npm run generate-types && npm run test

- uses: google-github-actions/release-please-action@v3
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ coverage
*.log
yarn.lock
types
.cspell.json
.cspell.json
.env*
8 changes: 7 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ coverage
.prettierignore
hardhat.config.ts
tsconfig.json
tsconfig.module.json
tsconfig.module.json
jest.config.json
yarn.lock
jest.setup.ts
package-lock.json
**/*.png
**/*.spec.*
38 changes: 38 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,44 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [3.1.1](https://github.com/lukso-network/tools-lsp-factory/compare/v3.1.0...v3.1.1) (2023-09-12)


### Bug Fixes

* use default SC version ([ed4a1a2](https://github.com/lukso-network/tools-lsp-factory/commit/ed4a1a2b85a0e1283ceb2142af64a1d74080d940))

## [3.1.0](https://github.com/lukso-network/tools-lsp-factory/compare/v3.0.0...v3.1.0) (2023-09-08)


### ⚠ BREAKING CHANGES

* upgrade lsp to v0.11.1

### Features

* upgrade lsp to v0.11.1 ([ccc61f8](https://github.com/lukso-network/tools-lsp-factory/commit/ccc61f855028c617767f726e317298ee65ee358a))


### Bug Fixes

* enable source map ([e3c60b3](https://github.com/lukso-network/tools-lsp-factory/commit/e3c60b331c213ce5ce6dec8479b577471345d76e))


### Miscellaneous Chores

* release 3.1.0 ([6955282](https://github.com/lukso-network/tools-lsp-factory/commit/6955282cd707d10493dda0acd3d02d91dc607bcc))

## [3.0.0](https://github.com/lukso-network/tools-lsp-factory/compare/v2.5.1...v3.0.0) (2023-08-17)

### ⚠ BREAKING CHANGES

- upgrade smart contracts to v0.10.3 ([#204](https://github.com/lukso-network/tools-lsp-factory/issues/204))

### Features

- upgrade smart contracts to v0.10.3 ([#204](https://github.com/lukso-network/tools-lsp-factory/issues/204)) ([db9d147](https://github.com/lukso-network/tools-lsp-factory/commit/db9d147df5b11dcb95c7a8249c683db49db2cce0))

### [2.5.1](https://github.com/lukso-network/tools-lsp-factory/compare/v2.5.0...v2.5.1) (2023-03-30)

### Bug Fixes
Expand Down
69 changes: 66 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,80 @@
npm install @lukso/lsp-factory.js
```

# Peer dependencies

| Provider | Dependency | Version | Browser | Node |
| -------- | ----------------- | ------- | ------- | ---- |
| pinata | @pinata/sdk | ^2.1.0 | ✅ | ✅ |
| pinata | cross-blob | ^3.0.2 | ❌ | ✅ |
| pinata | form-data | ^4.0.0 | ❌ | ✅ |
| pinata | form-data-encoder | ^3.0.0 | ❌ | ✅ |
| ipfs | ipfs-http-client | 52.0.3 | ✅ | ✅ |
| ipfs | ipfs-utils | 8.1.6 | ✅ | ✅ |

## Providers

Native open IPFS pinning (or local IPFS node upload)

```javascript
import { createIPFSUploader } from '@lukso/lsp-factory.js';
const uploadProvider = createIPFSUploader('https://api.2eff.lukso.dev');
```

Pinata node environment

```javascript
import { createPinataUploader } from '@lukso/lsp-factory.js';
const uploadProvider = createPinataUploader({});
```

Pinata browser environment

```javascript
import { createPinataBrowserUploader } from '@lukso/lsp-factory.js';
const uploadProvider = createPinataBrowserUploader({});
```

## Setup

```javascript
import { LSPFactory } from '@lukso/lsp-factory.js';
import { LSPFactory, createPrefixConverter, createIPFSUploader, addURLResolver, resolveURL } from '@lukso/lsp-factory.js';

const uploadProvider = createIPFSUploader('https://api.2eff.lukso.dev')
const provider = 'https://rpc.testnet.lukso.network'; // RPC url used to connect to the network

const lspFactory = new LSPFactory(provider, {
deployKey: '0x...'; // Private key of the account which will deploy UPs
chainId: 2828, // Chain Id of the network you want to connect to
signer: '0x...'; // Private key of the account which will deploy UPs
chainId: 4201, // Chain Id of the network you want to connect to
uploadProvider,
});

lspFactory.addURLResolver('ipfs:', createPrefixConverter('https://2eff.lukso.dev/ipfs'))
```

## Resolve URLs for uploaded files

```javascript
// Utility to conver URLs after addURLResolver has been called.
const url = lspFactory.resolveURL(
new URL('ipfs://QmPLqMFHxiUgYAom3Zg4SiwoxDaFcZpHXpCmiDzxrtjSGp')
);
console.log(url.toString());
```

## Implementing a custom upload provider

```javascript
const uploadProvider = async (data) => {
// upload data to ipfs here.
// The data can be a File (Blob) object (can have type to contain mime information)
// An AssetBuffer object (has mimeType)
// or a Buffer object

// Return a URL object containing the URL. For IPFS the protocol is "ipfs:"
// and the CID is in the hostname.
return new URL('ipfs://QmPLqMFHxiUgYAom3Zg4SiwoxDaFcZpHXpCmiDzxrtjSGp');
};
```

## Usage
Expand Down
8 changes: 2 additions & 6 deletions docs/classes/lsp4-digital-asset-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,9 @@ await LSP4DigitalAssetMetadata.uploadMetadata(

```javascript title="Uploading LSP4Metadata using upload options passed when instantiating LSPFactory"
const lspFactory = new LSPFactory(provider, {
deployKey: myDeployKey,
signer: myDeployKey,
chainId: myChainId,
ipfsGateway: {
host: 'ipfs.infura.io',
port: 5001,
protocol: 'https',
},
uploadProvider: createIPFSUploader('https://api.2eff.lukso.dev'),
});

await lspFactory.LSP4DigitalAssetMetadata.uploadMetadata({
Expand Down
8 changes: 4 additions & 4 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { LSPFactory } from '@lukso/lsp-factory.js';
const provider = 'https://rpc.testnet.lukso.network';

const lspFactory = new LSPFactory(provider, {
deployKey: '0x...', // Private key of the account which will deploy smart contracts
signer: '0x...', // Private key of the account which will deploy smart contracts
chainId: 2828,
});
```
Expand Down Expand Up @@ -117,15 +117,15 @@ When instantiating LSPFactory options can be passed to specify parameters such a

```javascript title="Instantiating LSPFactory with custom options set"
const lspFactory = new LSPFactory('https://rpc.testnet.lukso.network', {
deployKey: '0x...',
signer: '0x...',
chainId: 2828,
ipfsGateway: 'https://ipfs.infura.io:5001',
});
```

#### Deploy Key

`deployKey` is the private key which should sign the transactions sent by LSPFactory. This account must have enough gas to carry out the transactions.
`signer` is the private key which should sign the transactions sent by LSPFactory. This account must have enough gas to carry out the transactions.

If no value is set here, LSPFactory will attempt to sign transactions via a browser extension.

Expand All @@ -139,7 +139,7 @@ If no value is set here, LSPFactory will attempt to sign transactions via a brow

```javascript title="Instantiating LSPFactory with custom ipfsGateway options set"
const lspFactory = new LSPFactory('https://rpc.testnet.lukso.network', {
deployKey: '0x...',
signer: '0x...',
chainId: 2828,
ipfsGateway: {
host: 'ipfs.infura.io',
Expand Down
4 changes: 3 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ module.exports = async () => {
return {
roots: ['<rootDir>'],
transform: {
'^.+\\.tsx?$': [
'^.+\\.(tsx?|jsx?)$': [
'esbuild-jest',
{
sourcemap: true,
target: 'es2020',
},
],
},
transformIgnorePatterns: ['node_modules/(?!(form-data-encoder))/'],
collectCoverageFrom: ['src/**/*.ts'],
coveragePathIgnorePatterns: [
'node_modules',
Expand Down
3 changes: 3 additions & 0 deletions jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { waffleJest } from '@ethereum-waffle/jest';
import { config } from 'dotenv';

config({ path: '.env.test' });

jest.setTimeout(15000);
expect.extend(waffleJest);
Expand Down
Loading
Loading