Skip to content

Commit

Permalink
feat(token-definitions): signed/unsigned token definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasklim committed Apr 23, 2024
1 parent daff52f commit 4affd1d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/release-suite-definitions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ jobs:
run: |
yarn install
cd suite-common/token-definitions
yarn nfts simple ethereum
yarn nfts simple polygon-pos
yarn coins simple ethereum
yarn coins simple polygon-pos
yarn coins simple cardano
yarn coins simple solana
yarn coins advanced solana
yarn nfts simple ethereum jws
yarn nfts simple polygon-pos jws
yarn coins simple ethereum jws
yarn coins simple polygon-pos jws
yarn coins simple cardano jws
yarn coins simple solana jws
yarn coins advanced solana json
- name: Build and sign ${{ github.event.inputs.environment }} token-definitions files
if: ${{ github.event.inputs.environment == 'production' && github.ref == 'refs/heads/develop' }}
Expand All @@ -55,13 +55,13 @@ jobs:
run: |
yarn install
cd suite-common/token-definitions
yarn nfts simple ethereum
yarn nfts simple polygon-pos
yarn coins simple ethereum
yarn coins simple polygon-pos
yarn coins simple cardano
yarn coins simple solana
yarn coins advanced solana
yarn nfts simple ethereum jws
yarn nfts simple polygon-pos jws
yarn coins simple ethereum jws
yarn coins simple polygon-pos jws
yarn coins simple cardano jws
yarn coins simple solana jws
yarn coins advanced solana json
- name: Upload ${{ github.event.inputs.environment }} token-definitions files
if: ${{ github.ref == 'refs/heads/develop' }}
Expand Down
9 changes: 5 additions & 4 deletions suite-common/token-definitions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ Scripts:
- `simple` (used for Suite)
- `advanced` (planned to be used for Solana token symbols and names)
- and chain

- `ethereum`, `polygon-pos`, `solana`,...

- e.g. `yarn coins advanced solana` and you get `jws` in format:
- and file type
- `jws` for signed data
- `json` for unsigned data
- e.g. `yarn coins advanced solana json` and you get `json` in format:

```
{
Expand All @@ -40,7 +41,7 @@ Scripts:
}
```

- e.g. `yarn nfts simple polygon-pos` and you get `jws` in format:
- e.g. `yarn nfts simple polygon-pos jws` and you get `jws` in format:

```
[
Expand Down
23 changes: 17 additions & 6 deletions suite-common/token-definitions/scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import { fetchNftData } from './utils/fetchNft';
import { signData } from './utils/sign';
import { validateStructure } from './utils/validate';
import { FILES_PATH, DEFINITIONS_FILENAME_SUFFIX } from './constants';
import { TokenStructure } from '../src/types';
import { fetchCoinData } from './utils/fetchCoins';
import { TokenStructure } from '../src/types';

const main = async () => {
const argv = process.argv.slice(2);

const type: string = argv[0];
const structure: string = argv[1];
const assetPlatformId: string = argv[2];
const fileType: string = argv[3];

if (!type || !['nft', 'coin'].includes(type)) {
throw new Error('Missing type, please specify "nft" or "coin"');
Expand All @@ -30,6 +31,10 @@ const main = async () => {
);
}

if (!fileType || !['json', 'jws'].includes(fileType)) {
throw new Error('Missing file type, please specify "json" or "jws"');
}

let data: TokenStructure;
if (type === 'nft') {
data = await fetchNftData(assetPlatformId, structure);
Expand All @@ -55,17 +60,23 @@ const main = async () => {

validateStructure(data, structure);

const signedData = signData(data);

const destinationFile = join(
FILES_PATH,
`${assetPlatformId}.${structure}.${type}.${DEFINITIONS_FILENAME_SUFFIX}.jws`,
`${assetPlatformId}.${structure}.${type}.${DEFINITIONS_FILENAME_SUFFIX}.${fileType}`,
);

fs.mkdirSync(FILES_PATH, { recursive: true });
fs.writeFileSync(destinationFile, signedData);

console.log('Signed definitions saved to', destinationFile);
if (fileType === 'jws') {
const signedData = signData(data);
fs.writeFileSync(destinationFile, signedData);

console.log('JWS definitions saved to', destinationFile);
} else {
fs.writeFileSync(destinationFile, JSON.stringify(data));

console.log('JSON definitions saved to', destinationFile);
}
};

main();

0 comments on commit 4affd1d

Please sign in to comment.