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

Key Dependent Signer Function APIs #85

Merged
merged 14 commits into from
Feb 21, 2023
Merged
1 change: 1 addition & 0 deletions manta-js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
## [Unreleased]

### Added
- [\#85](https://github.com/Manta-Network/sdk/pull/85) Key-dependent signer function APIs.

### Changed

Expand Down
8 changes: 4 additions & 4 deletions manta-js/examples/asset-webpack-ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { web3Accounts, web3Enable, web3FromSource } from '@polkadot/extension-da

async function main() {
await toPrivateOnlySignTest();
await toPrivateTest();
await privateTransferTest();
await toPublicTest();
await publicTransferTest();
// await toPrivateTest();
// await privateTransferTest();
// await toPublicTest();
// await publicTransferTest();
console.log("END");
}

Expand Down
2 changes: 1 addition & 1 deletion manta-js/examples/asset-webpack-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"copy-webpack-plugin": "^11.0.0",
"crypto-browserify": "^3.12.0",
"declaration-bundler-webpack-plugin": "^1.0.3",
"manta.js": "file:../../package",
"manta.js": "../../package",
"ts-loader": "^9.4.1",
"typescript": "^4.9.3"
},
Expand Down
2,002 changes: 987 additions & 1,015 deletions manta-js/examples/asset-webpack-ts/yarn.lock

Large diffs are not rendered by default.

39 changes: 19 additions & 20 deletions manta-js/package/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ import * as $ from 'scale-codec';
import { u8aToU8a } from '@polkadot/util';


function dataURItoBlob(dataURI) {
// convert base64 to raw binary data held in a string
const byteString = atob(dataURI.split(',')[1]);

// separate out the mime component
const mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];

// write the bytes of the string to an ArrayBuffer
const arrayBuffer = new ArrayBuffer(byteString.length);
const _ia = new Uint8Array(arrayBuffer);
for (let i = 0; i < byteString.length; i++) {
_ia[i] = byteString.charCodeAt(i);
}
// function dataURItoBlob(dataURI) {
// // convert base64 to raw binary data held in a string
// const byteString = atob(dataURI.split(',')[1]);

const dataView = new DataView(arrayBuffer);
const blob = new Blob([dataView], { type: mimeString });
return blob;
}
// // separate out the mime component
// const mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];

// // write the bytes of the string to an ArrayBuffer
// const arrayBuffer = new ArrayBuffer(byteString.length);
// const _ia = new Uint8Array(arrayBuffer);
// for (let i = 0; i < byteString.length; i++) {
// _ia[i] = byteString.charCodeAt(i);
// }

// const dataView = new DataView(arrayBuffer);
// const blob = new Blob([dataView], { type: mimeString });
// return blob;
// }

const formatStorageKey = (key) => `storage_data_${key}`;

Expand Down Expand Up @@ -272,13 +272,12 @@ export default class Api {
/**
* read storage data from local
* @param {String} key `${network.toString()}`
* @returns {Promise<Blob>}
* @returns {String}
*/
async loadStorageDataFromLocal(key) {
// in Extension, this api will be: chrome.storage.local.get
// will decrypt data with a user key
const data = localStorage.getItem(formatStorageKey(key));
return data ? dataURItoBlob(data) : null;
return localStorage.getItem(formatStorageKey(key)) || null;
}
}

Expand Down
Loading