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

Revamp to likecoin-js #22

Merged
merged 23 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
df52951
🚚 Move likepay to subdirectory
williamchong Nov 3, 2021
5fb1f03
🚚 Move likepay as subpackage
williamchong Nov 6, 2021
fc06e35
🔧 Init repo config
williamchong Nov 6, 2021
5119365
✨ Add arweave api logic
williamchong Nov 6, 2021
ddfd0b6
✨ Add iscn and tx code
williamchong Nov 8, 2021
4366953
✨ Add submit arweave iscn function
williamchong Nov 8, 2021
9f40474
✨ Expose queryClient for ISCN module
williamchong Nov 10, 2021
b5d0262
🐛 Fix likepay qr not buildable
williamchong Nov 15, 2021
a1936a0
🔧 Fix not buildable
williamchong Nov 15, 2021
f33c6ac
🔧 Add webpack umd build
williamchong Nov 15, 2021
9b2a4cb
📝 Update likepay document
williamchong Nov 15, 2021
ce4080b
📝 Add basic README.md
williamchong Nov 15, 2021
27b7a69
🔧 Fix likepay commonjs build
williamchong Nov 16, 2021
404bff1
✅ Add arweave example
williamchong Nov 16, 2021
f14097c
🐛 Fix IPFS hash was not added to ISCN after submit to arweave
williamchong Nov 19, 2021
b9a657b
✨ Add query like tx and expose tx and iscn module
williamchong Nov 19, 2021
8b5104d
📝 Add iscn and tx example
williamchong Nov 19, 2021
620053f
🔥 Remove unused test asset
williamchong Nov 22, 2021
56007af
🐛 Fix form issue in umd build
williamchong Nov 22, 2021
0b9ab21
📝 Add arweave browser example
williamchong Nov 22, 2021
ef84847
✨ Expose sign and query wrapper for iscn module
williamchong Nov 22, 2021
3630dd2
📝 Update iscn module example
williamchong Nov 23, 2021
92e0e64
✏️ Fix type and readme typo
williamchong Nov 26, 2021
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: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Changelog
## [Unreleased]

## [0.0.1]
### Added
- Arweave, transaction and ISCN features for LikeCoin chain and like.co API
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
# LIKE pay
Easily receive payments in LIKE in your websites
# LikeCoin-js
> JavaScript SDK for LikeCoin features and like.co API

[![NPM Version][npm-image]][npm-url]

## Install

```bash
npm i -S @likecoin/likecoin-js
```

## Usage
https://docs.like.co/developer/like-pay/sdk/usage

## Reference
https://docs.like.co/developer/like-pay/sdk/reference
Please refer to `example` for usage examples

```

[npm-image]: https://img.shields.io/npm/v/@likecoin/likecoin.svg
[npm-url]: https://www.npmjs.com/package/@likecoin/likecoin
76 changes: 76 additions & 0 deletions examples/arweave/browser/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>LIKE pay</title>
<script src="../../../dist/umd/likecoin.umd.js"></script>
</head>

<body>
<div>
<form id="form1">
<h2>ISCN file uploader</h2>
<input type="file" class="filepicker" /><br />
<label for="name">ISCN Name</label><br />
<input class="name" name="name" value="ISCN Demo" /><br />
<label for="description">ISCN description</label><br />
<input
class="description"
name="description"
value="Simple description"
/><br />
<button type="submit">Submit</button><br />
</form>
</div>
<div>
<form id="form2">
<h2>ISCN folder uploader</h2>
<input type="file" class="filepicker" webkitdirectory multiple /><br />
<label for="name">ISCN Name</label><br />
<input class="name" name="name" value="ISCN Folder Demo" /><br />
<label for="description">ISCN description</label><br />
<input
class="description"
name="description"
value="Simple description"
/><br />
<button type="submit">Submit</button><br />
</form>
</div>
<script>
const mnemonic =
"surround miss nominee dream gap cross assault thank captain prosper drop duty group candy wealth weather scale put";

async function uploadToARISCN(formId) {
const files = document.querySelector(`#${formId} .filepicker`).files;
if (!files) return;
const name = document.querySelector(`#${formId} .name`);
const description = document.querySelector(`#${formId} .description`);

try {
const signer = await likecoin.tx.createSignerFromMenomics(mnemonic);
const [from] = await signer.getAccounts();
const res1 = await likecoin.arweave.submitToArweaveAndISCN(
files,
{ name, description },
signer,
from.address
);
console.log(res1);
} catch (err) {
console.error(err);
}
}
document.getElementById("form1").addEventListener("submit", (e) => {
e.preventDefault();
uploadToARISCN('form1');
});
document.getElementById("form2").addEventListener("submit", (e) => {
e.preventDefault();
uploadToARISCN('form2');
});
</script>
</body>
</html>
36 changes: 36 additions & 0 deletions examples/arweave/node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const likecoin = require('../../../dist/commonjs');

const path = require('path');
const { DirectSecp256k1HdWallet } = require('@cosmjs/proto-signing');

const mnemonic = 'surround miss nominee dream gap cross assault thank captain prosper drop duty group candy wealth weather scale put';

async function main() {
try {
const signer = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic);
const [from] = await signer.getAccounts();
const res1 = await likecoin.arweave.submitToArweaveAndISCN(
path.resolve(__dirname, '../../asset/upload/index.html'),
{
name: 'Index',
},
signer,
from.address,
);
console.log(res1);

const res2 = await likecoin.arweave.submitToArweaveAndISCN(
path.resolve(__dirname, '../../asset/upload'),
{
name: 'Index + Assets',
},
signer,
from.address,
);
console.log(res2);
} catch (err) {
console.error(err);
}
}

main();
Binary file added examples/asset/upload/asset/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions examples/asset/upload/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>blah</title>
</head>
<body>
<img src="./asset/image.png">
<p>I'm the html content!</p>
</body>
</html>
8 changes: 0 additions & 8 deletions examples/browser/js/like-pay.js

This file was deleted.

50 changes: 50 additions & 0 deletions examples/iscn/node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const { DirectSecp256k1HdWallet } = require('@cosmjs/proto-signing');
const likecoin = require('../../../dist/commonjs');

const mnemonic = 'surround miss nominee dream gap cross assault thank captain prosper drop duty group candy wealth weather scale put';

async function main() {
try {
// https://github.com/likecoin/iscn-js samples
// Query ISCN by ID
const res1 = await likecoin.iscn.queryRecordsById('iscn://likecoin-chain/dLbKMa8EVO9RF4UmoWKk2ocUq7IsxMcnQL1_Ps5Vg80/1');
console.log(res1);

const client = likecoin.iscn.queryClient;
// Query ISCN by owner
const res2 = await client.queryRecordsByOwner('cosmos1sf2sc6t37xhd3m0dcaq6h5dz22mtru2ugdwp0v');
console.log(res2);

const signer = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic);

const ISCNPayload = {
contentFingerprints: [
'hash://sha256/9564b85669d5e96ac969dd0161b8475bbced9e5999c6ec598da718a3045d6f2e',
],
stakeholders: [
{
entity: {
'@id': 'did:cosmos:5sy29r37gfxvxz21rh4r0ktpuc46pzjrmz29g45',
name: 'Chung Wu',
},
rewardProportion: 95,
contributionType: 'http://schema.org/author',
},
],
type: 'Article',
name: '使用矩陣計算遞歸關係式',
usageInfo: 'https://creativecommons.org/licenses/by/4.0',
keywords: ['matrix', 'recursion'],
};

const res = await likecoin.iscn.createISCNRecord(signer, ISCNPayload);
console.log(res);

const iscnID = await client.queryISCNIdsByTx(res.transactionHash);
console.log(iscnID);
} catch (err) {
console.error(err);
}
}

main();
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>LIKE pay</title>
<script src="./js/like-pay.js"></script>
<script src="../../../dist/umd/likecoin.umd.js"></script>
</head>

<body>
Expand All @@ -17,13 +17,13 @@
<script>
function init() {
/* create payment qrcode, DOM selector, likerId, LIKE amount */
likePay.createPaymentQRCode('#likepay', 'ckxpress', 1)
likecoin.likepay.createPaymentQRCode('#likepay', 'ckxpress', 1)
.then((tx) => {
/* returns after tx complete, shows tx completion */
console.log(tx);
return tx;
})
.then((tx) => likePay.getTx(tx.id)) // get tx by id
.then((tx) => likecoin.likePay.getTx(tx.id)) // get tx by id
.then((tx) => console.log(tx)); // tx info
}
init();
Expand Down
18 changes: 18 additions & 0 deletions examples/tx/node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const likecoin = require('../../../dist/commonjs');

const { DirectSecp256k1HdWallet } = require('@cosmjs/proto-signing');

const mnemonic = 'surround miss nominee dream gap cross assault thank captain prosper drop duty group candy wealth weather scale put';

async function main() {
try {
const signer = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic);
const [from] = await signer.getAccounts();
const res = await likecoin.tx.sendLIKE(from.address, 'cosmos1rclg677y2jqt8x4ylj0kjlqjjmnn6w6304rrtc', '100', signer, 'test');
await likecoin.tx.queryLIKETransaction(res.transactionHash);
} catch (err) {
console.error(err);
}
}

main();
6 changes: 6 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: ['/node_modules/', 'dist/module'],
};
Loading