Skip to content

Commit

Permalink
Key Dependent Signer Function APIs (#85)
Browse files Browse the repository at this point in the history
* changed branch

* new signer + load/drop accounts

* new methods

* changelog

* mnemonic from phrase

* fix: update signer initial

* fix: update signer initial

* changed from parameters to full parameters

* new storage methods

* get and set storage methods for wallet + docs

* fix: init signer

* fix: init signer bugs

* fix: init Parameters & ProvingContext

---------

Co-authored-by: Daniel <danielnickreal@gmail.com>
  • Loading branch information
SupremoUGH and DanielZhangReal authored Feb 21, 2023
1 parent 5861636 commit acfbada
Show file tree
Hide file tree
Showing 11 changed files with 1,746 additions and 4,088 deletions.
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

0 comments on commit acfbada

Please sign in to comment.