Skip to content

Commit

Permalink
Merge pull request #25 from dimitrov-d/master
Browse files Browse the repository at this point in the history
3.0.0 (Phala SDK, Substrate NFTs, Social SDK)
  • Loading branch information
MoMannn committed Apr 9, 2024
2 parents eb6b379 + 4966970 commit 91e7995
Show file tree
Hide file tree
Showing 33 changed files with 1,148 additions and 155 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apillon-web3-tools",
"version": "2.0.0",
"version": "3.0.0",
"description": "Monorepo for Apillon tools",
"author": "Apillon",
"license": "MIT",
Expand Down
19 changes: 10 additions & 9 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,7 @@ apillon storage list-objects --bucket-uuid "123e4567-e89b-12d3-a456-426655440000
"updateTime": "2023-11-23T08:55:46.000Z",
"uuid": "14a7a891-877c-41ac-900c-7382347e1e77",
"name": "index.html",
"CID": "QmWX5CcNvnaVmgGBn4o82XW9uW1uLvsHQDdNrANrQeSdXm",
"CIDv1": "bafybeidzrd7p5ddj67j2mud32cbnze2c7b2pvbhn...",
"CID": "bafybeidzrd7p5ddj67j2mud32cbnze2c7b2pvbhn...",
"status": "AVAILABLE_ON_IPFS_AND_REPLICATED",
"directoryUuid": null,
"type": "FILE",
Expand Down Expand Up @@ -350,8 +349,7 @@ apillon storage list-files --bucket-uuid "123e4567-e89b-12d3-a456-426655440000"
"createTime": "2023-11-15T09:58:04.000Z",
"updateTime": "2023-11-15T09:58:10.000Z",
"name": "style.css",
"CID": "QmWX5CcNvnaVmgGBn4o82XW9uW1uLvsHQDdNrANrQeSdXm",
"CIDv1": "bafybeidzrd7p5ddj67j2mud32cbnze2c7b2pvbag...",
"CID": "bafybeidzrd7p5ddj67j2mud32cbnze2c7b2pvbag...",
"status": "AVAILABLE_ON_IPFS_AND_REPLICATED",
"directoryUuid": null,
"type": "FILE",
Expand Down Expand Up @@ -438,7 +436,7 @@ Lists all IPNS records for a specific bucket.

**Example**
```sh
apillon ipns list --bucket-uuid "123e4567-e89b-12d3-a456-426655440000"
apillon storage ipns list --bucket-uuid "123e4567-e89b-12d3-a456-426655440000"
```

**Example response**
Expand Down Expand Up @@ -484,41 +482,44 @@ Creates a new IPNS record for a specific bucket.

**Example**
```sh
apillon ipns create --bucket-uuid "123e4567-e89b-12d3-a456-426655440000" --name "my-ipns-record" --cid "QmWX5CcNvnaVmgGBn4o82XW9uW1uLvsHQDdNrANrQeSdXm"
apillon storage ipns create --bucket-uuid "123e4567-e89b-12d3-a456-426655440000" --name "my-ipns-record" --cid "QmWX5CcNvnaVmgGBn4o82XW9uW1uLvsHQDdNrANrQeSdXm"
```

#### `storage ipns get`
Retrieves information about a specific IPNS record.

**Options**
- `-b, --bucket-uuid <uuid>`: UUID of the bucket.
- `-i, --ipns-uuid <uuid>`: UUID of the IPNS record.

**Example**
```sh
apillon ipns get --ipns-uuid "123e4567-e89b-12d3-a456-426655440000"
apillon storage ipns get --ipns-uuid "123e4567-e89b-12d3-a456-426655440000"
```

#### `storage ipns publish`
Publishes an IPNS record to IPFS and links it to a CID.

**Options**
- `-b, --bucket-uuid <uuid>`: UUID of the bucket.
- `-i, --ipns-uuid <uuid>`: UUID of the IPNS record.
- `-c, --cid <string>`: CID to which this IPNS name will point.

**Example**
```sh
apillon ipns publish --ipns-uuid "123e4567-e89b-12d3-a456-426655440000" --cid "QmWX5CcNvnaVmgGBn4o82XW9uW1uLvsHQDdNrANrQeSdXm"
apillon storage ipns publish --ipns-uuid "123e4567-e89b-12d3-a456-426655440000" --cid "QmWX5CcNvnaVmgGBn4o82XW9uW1uLvsHQDdNrANrQeSdXm"
```

#### `storage ipns delete`
Deletes an IPNS record from a specific bucket.

**Options**
- `-b, --bucket-uuid <uuid>`: UUID of the bucket.
- `-i, --ipns-uuid <uuid>`: UUID of the IPNS record.

**Example**
```sh
apillon ipns delete --ipns-uuid "123e4567-e89b-12d3-a456-426655440000"
apillon storage ipns delete --ipns-uuid "123e4567-e89b-12d3-a456-426655440000"
```

## NFT Commands
Expand Down
131 changes: 116 additions & 15 deletions packages/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ as well as compresses multi step flows into single operations.

## Requirements

- npm 8.4.0 or higher
- node.js 16.17.0 or higher
- npm 10.0.0 or higher
- node.js 20.0.0 or higher
- Apillon API key and secret

## Getting started
Expand Down Expand Up @@ -46,6 +46,12 @@ View each individual module examples in the sections below.

This wiki only contains the basic installation and examples of SDK usage. For additional information on using the SDK, see the [Detailed SDK documentation](https://sdk-docs.apillon.io/).

### Examples

Examples for using Apillon can be found in a demo repo [here](https://github.com/Apillon/apillon-sdk-demo). Instructions on running the examples are in the [README file](https://github.com/Apillon/apillon-sdk-demo/blob/master/README.md).

> You can run examples directly in your browser via [CodeSandbox](https://codesandbox.io/p/github/Apillon/apillon-sdk-demo/master).
## Hosting

Hosting module encapsulates functionalities for Hosting service available on Apillon dashboard.
Expand Down Expand Up @@ -76,7 +82,7 @@ import * as fs from 'fs';
const hosting = new Hosting({
key: 'yourApiKey',
secret: 'yourApiSecret',
logLevel: LogLevel.NONE,
logLevel: LogLevel.VERBOSE,
});

// list all websites
Expand Down Expand Up @@ -134,7 +140,7 @@ import * as fs from 'fs';
const storage = new Storage({
key: 'yourApiKey',
secret: 'yourApiSecret',
logLevel: LogLevel.NONE,
logLevel: LogLevel.VERBOSE,
});

// list buckets
Expand Down Expand Up @@ -190,7 +196,7 @@ import { Storage, LogLevel } from '@apillon/sdk';
const storage = new Storage({
key: 'yourApiKey',
secret: 'yourApiSecret',
logLevel: LogLevel.NONE,
logLevel: LogLevel.VERBOSE,
});

// create and instance of a bucket directly through uuid
Expand Down Expand Up @@ -235,11 +241,11 @@ import {
const nft = new Nft({
key: 'yourApiKey',
secret: 'yourApiSecret',
logLevel: LogLevel.NONE,
logLevel: LogLevel.VERBOSE,
});

// create a new collection
const collection1 = await nft.create({
let collection = await nft.create({
collectionType: CollectionType.GENERIC,
chain: EvmChain.MOONBEAM,
name: 'SpaceExplorers',
Expand All @@ -258,20 +264,31 @@ const collection1 = await nft.create({
dropPrice: 0.05,
dropReserve: 100,
});
// or create a substrate collection
const substrateCollection = await nft.createSubstrate({
collectionType: CollectionType.GENERIC,
chain: SubstrateChain.ASTAR,
name: 'SpaceExplorers',
symbol: 'SE',
...
});

// check if collection is deployed - available on chain
if (collection1.collectionStatus == CollectionStatus.DEPLOYED) {
console.log('Collection deployed: ', collection1.transactionHash);
if (collection.collectionStatus == CollectionStatus.DEPLOYED) {
console.log('Collection deployed: ', collection.transactionHash);
}

// search through collections
await nft.listCollections({ search: 'My NFT' });

// create and instance of collection directly through uuid
const collection = await nft.collection('uuid').get();
collection = await nft.collection('uuid').get();

// mint a new nft in the collection
await collection.mint('0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD', 1);
await collection.mint({
receivingAddress: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
quantity: 1,
});

// nest mint a new nft if collection type is NESTABLE
await collection.nestMint(collection.uuid, 1, 1);
Expand All @@ -292,7 +309,6 @@ await collection.transferOwnership(
);
```


## Identity

Identity module encapsulates functionalities for validating EVM and Polkadot wallet signatures, as well as fetching Polkadot Identity data for any wallet.
Expand All @@ -302,14 +318,13 @@ For detailed hosting SDK method, class and property documentation visit [SDK ide
### Usage example

```ts
import { Identity } from './modules/identity/identity';
import { LogLevel } from './types/apillon';
import { Identity, LogLevel } from '@apillon/sdk';

// Note: for signature-related methods API config is not required
const identity = new Identity({
key: 'yourApiKey',
secret: 'yourApiSecret',
logLevel: LogLevel.NONE,
logLevel: LogLevel.VERBOSE,
});

// obtain on-chain identity data for a Polkadot wallet
Expand Down Expand Up @@ -364,4 +379,90 @@ async function validatePolkadotWalletSignature() {
}

```
## Computing

The Computing module provides functionalities for managing computing contracts, including creating contracts, listing contracts, and interacting with specific contracts for operations like encryption and ownership transfer.

### Usage example

```ts
import { Computing } from '@apillon/sdk';

const computing = new Computing({
key: 'yourApiKey',
secret: 'yourApiSecret',
});

// List all computing contracts
const contracts = await computing.listContracts();

// Create a new computing contract
const newContract = await computing.createContract({
name: 'New Contract',
description: 'Description of the new contract',
bucket_uuid,
contractData: {
nftContractAddress: '0xabc...',
nftChainRpcUrl: ChainRpcUrl.ASTAR,
},
});

// Interact with a specific computing contract
const contract = computing.contract(newContract.uuid);

// Get details of the contract
const contractDetails = await contract.get();

// List transactions of the contract
const transactions = await contract.listTransactions();

// Encrypt a file and upload it to the associated bucket
const encryptionResult = await contract.encryptFile({
fileName: 'example.txt',
content: Buffer.from('Hello, world!'),
nftId: 1, // NFT ID used for decryption authentication
});

// Transfer ownership of the contract
const newOwnerAddress = '0xNewOwnerAddress';
const successResult = await contract.transferOwnership(newOwnerAddress);
console.log(
`Ownership transfer was ${successResult ? 'successful' : 'unsuccessful'}.`,
);
```

## Social

The Social module provides functionalities for managing social hubs and channels within the Apillon platform. This includes creating, listing, and interacting with hubs and channels. In the background it utilizes Grill.chat, a mobile-friendly, anonymous chat application powered by Subsocial.

### Usage example

```ts
import { Social } from '@apillon/sdk';

const social = new Social({ key: 'yourApiKey', secret: 'yourApiSecret' });
// Create a new hub
const hub = await social.createHub({
name: 'Apillon Hub',
about: 'Hub for Apillon channels',
tags: 'apillon,web3,build',
});

// Get a specific hub by UUID
const hubDetails = await social.hub(hub.uuid).get();
// List all Hubs
const hubs = await social.listHubs();

// Create a new channel within a hub
const channel = await social.createChannel({
title: 'Web3 Channel',
body: "Let's discuss Web3",
tags: 'web3,crypto',
hubUuid: hub.uuid,
});

// Get a specific channel by UUID
const channelDetails = await social.channel(channel.uuid).get();
// List all channels within a Hub
const channels = await social.listChannels({ hubUuid: hub.uuid });
```
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@apillon/sdk",
"description": "▶◀ Apillon SDK for NodeJS ▶◀",
"version": "2.0.1",
"version": "3.0.0",
"author": "Apillon",
"license": "MIT",
"main": "./dist/index.js",
Expand Down
6 changes: 6 additions & 0 deletions packages/sdk/src/docs-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './types/nfts';
export * from './types/hosting';
export * from './types/storage';
export * from './types/identity';
export * from './types/computing';
export * from './lib/apillon';
export * from './modules/storage/storage';
export * from './modules/storage/storage-bucket';
Expand All @@ -15,3 +16,8 @@ export * from './modules/hosting/hosting-website';
export * from './modules/nft/nft';
export * from './modules/nft/nft-collection';
export * from './modules/identity/identity';
export * from './modules/computing/computing';
export * from './modules/computing/computing-contract';
export * from './modules/social/social';
export * from './modules/social/social-hub';
export * from './modules/social/social-channel';
2 changes: 2 additions & 0 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ export * from './modules/storage/storage';
export * from './modules/hosting/hosting';
export * from './modules/nft/nft';
export * from './modules/identity/identity';
export * from './modules/computing/computing';
export * from './modules/social/social';
2 changes: 2 additions & 0 deletions packages/sdk/src/lib/apillon-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export class ApillonApi {
}
},
);

return config;
}

public static async get<T>(url: string, config?: any): Promise<T> {
Expand Down
7 changes: 4 additions & 3 deletions packages/sdk/src/lib/apillon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ export interface ApillonConfig {
}

export class ApillonModule {
protected config: ApillonConfig;

public constructor(config?: ApillonConfig) {
ApillonApi.initialize(config);
this.config = ApillonApi.initialize(config);
ApillonLogger.initialize(
config?.debug ? LogLevel.VERBOSE : config?.logLevel || LogLevel.ERROR,
);
Expand Down Expand Up @@ -71,8 +73,7 @@ export class ApillonModel {
protected populate(data: object) {
if (data != null) {
Object.keys(data || {}).forEach((key) => {
const prop = this[key];
if (prop === null) {
if (this[key] === null) {
this[key] = data[key];
}
});
Expand Down
Loading

0 comments on commit 91e7995

Please sign in to comment.