-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #597 from magiclabs/makrandgupta-sc-82686-revive-h…
…edera-extension [82686] revive hedera extension
- Loading branch information
Showing
14 changed files
with
226 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/node_modules | ||
/coverage | ||
/dist | ||
/.eslintrc.js | ||
/jest.config.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
extends: ['../../../.eslintrc.js'], | ||
parserOptions: { | ||
project: ['./tsconfig.json'], | ||
tsconfigRootDir: __dirname, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
'*.{ts,tsx}': | ||
- eslint --fix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('../../../.prettierrc.js'); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018-present Magic Labs, Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "@magic-ext/hedera", | ||
"version": "0.1.0", | ||
"description": "magic hedera extension", | ||
"author": "Magic <[email protected]> (https://magic.link/)", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/magiclabs/magic-js" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"target": "neutral", | ||
"cdnGlobalName": "MagicHederaExtension", | ||
"main": "./dist/cjs/index.js", | ||
"module": "./dist/es/index.js", | ||
"types": "./dist/types/index.d.ts", | ||
"jsdelivr": "./dist/extension.js", | ||
"react-native": "./dist/react-native/index.native.js", | ||
"exports": { | ||
"import": "./dist/es/index.mjs", | ||
"require": "./dist/cjs/index.js" | ||
}, | ||
"externals": { | ||
"include": [ | ||
"@magic-sdk/commons" | ||
] | ||
}, | ||
"devDependencies": { | ||
"@magic-sdk/commons": "^14.6.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { HederaExtension } from './index'; | ||
|
||
export default HederaExtension; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './index'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Extension } from '@magic-sdk/commons'; | ||
import { HederaConfig, HederaPayloadMethod } from './types'; | ||
|
||
export * from './utils'; | ||
|
||
export class HederaExtension extends Extension.Internal<'hedera', any> { | ||
name = 'hedera' as const; | ||
config: any = {}; | ||
network: string; | ||
|
||
constructor(public hederaConfig: HederaConfig) { | ||
super(); | ||
|
||
this.network = hederaConfig.network; | ||
this.config = { | ||
chainType: 'HEDERA', | ||
options: { | ||
network: hederaConfig.network, | ||
}, | ||
}; | ||
} | ||
|
||
public async getPublicKey() { | ||
return this.request(this.utils.createJsonRpcRequestPayload(HederaPayloadMethod.HederaGetPublicKey, [])); | ||
} | ||
|
||
public async sign(message: Uint8Array) { | ||
return this.request(this.utils.createJsonRpcRequestPayload(HederaPayloadMethod.HederaSign, [{ message }])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface HederaConfig { | ||
network: string; | ||
} | ||
|
||
export enum HederaPayloadMethod { | ||
HederaSign = 'hedera_sign', | ||
HederaGetPublicKey = 'hedera_getPublicKey', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @param {Uint8Array} data | ||
* @returns {string} | ||
*/ | ||
export function encode(data: Uint8Array) { | ||
return Buffer.from(data).toString('hex'); | ||
} | ||
|
||
/** | ||
* @param {string} text | ||
* @returns {Uint8Array} | ||
*/ | ||
export function decode(text: string) { | ||
const str = text.startsWith('0x') ? text.substring(2) : text; | ||
return Buffer.from(str, 'hex'); | ||
} | ||
|
||
export function shuffle(array: any) { | ||
let currentIndex = array.length; | ||
let temporaryValue; | ||
let randomIndex; | ||
|
||
// While there remain elements to shuffle... | ||
while (currentIndex !== 0) { | ||
randomIndex = Math.floor(Math.random() * currentIndex); | ||
currentIndex -= 1; | ||
|
||
// And swap it with the current element. | ||
temporaryValue = array[currentIndex]; | ||
// eslint-disable-next-line no-param-reassign | ||
array[currentIndex] = array[randomIndex]; | ||
// eslint-disable-next-line no-param-reassign | ||
array[randomIndex] = temporaryValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "../../../tsconfig.settings.json", | ||
"exclude": [ | ||
"temple" | ||
] | ||
} | ||
|
Oops, something went wrong.