Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 11 additions & 2 deletions packages/@magic-ext/polkadot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,24 @@
"types": "./dist/types/index.d.ts",
"jsdelivr": "./dist/extension.js",
"exports": {
"types": "./dist/types/index.d.ts",
"import": "./dist/es/index.mjs",
"require": "./dist/cjs/index.js"
},
"externals": {
"include": [
"@magic-sdk/commons"
"@magic-sdk/provider"
]
},
"devDependencies": {
"@magic-sdk/commons": "^17.2.0"
"@magic-sdk/provider": "^21.2.0",
"@polkadot/types": "^10.10.1",
"@polkadot/util": "^12.5.1"
},
"dependencies": {
"@polkadot/api": "^10.10.1"
},
"peerDependencies": {
"@polkadot/api": "^10.10.1"
}
}
6 changes: 4 additions & 2 deletions packages/@magic-ext/polkadot/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Extension } from '@magic-sdk/commons';
import { PolkadotConfig, ConfigType } from './type';
import { Extension } from '@magic-sdk/provider';
import type { ConfigType, PolkadotConfig } from './type';

export { MagicSigner } from './magic-signer';

export class PolkadotExtension extends Extension.Internal<'polkadot', PolkadotConfig> {
name = 'polkadot' as const;
Expand Down
45 changes: 45 additions & 0 deletions packages/@magic-ext/polkadot/src/magic-signer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { Signer } from '@polkadot/api/types';
import type { ISubmittableResult, SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types';
import type { HexString } from '@polkadot/util/types';
import type { H256 } from '@polkadot/types/interfaces';
import { Extension, InstanceWithExtensions, SDKBase } from '@magic-sdk/provider';
import { PolkadotExtension } from '.';

type MagicInstnace = InstanceWithExtensions<SDKBase, [PolkadotExtension, ...Extension[]]>;

export class MagicSigner implements Signer {
private magic: MagicInstnace;
private nextId = 0;

constructor(magic: MagicInstnace) {
this.magic = magic;
}

/**
* @description signs an extrinsic payload from a serialized form
*/
signPayload = async (payload: SignerPayloadJSON) => {
const signature = await this.magic.rpcProvider.send<string>('pdt_signPayload', [payload]);

return {
id: this.nextId++,
signature: signature as HexString,
};
};
/**
* @description signs a raw payload, only the bytes data as supplied
*/
signRaw = async (raw: SignerPayloadRaw) => {
const signature = await this.magic.rpcProvider.send<HexString>('pdt_signRaw', [raw]);

return {
id: this.nextId++,
signature,
};
};

/**
* @description Receives an update for the extrinsic signed by a `signer.sign`
*/
update?: (id: number, status: H256 | ISubmittableResult) => void;
}
Loading