File tree Expand file tree Collapse file tree 4 files changed +672
-53
lines changed
packages/@magic-ext/polkadot Expand file tree Collapse file tree 4 files changed +672
-53
lines changed Original file line number Diff line number Diff line change 18
18
"types" : " ./dist/types/index.d.ts" ,
19
19
"jsdelivr" : " ./dist/extension.js" ,
20
20
"exports" : {
21
+ "types" : " ./dist/types/index.d.ts" ,
21
22
"import" : " ./dist/es/index.mjs" ,
22
23
"require" : " ./dist/cjs/index.js"
23
24
},
24
25
"externals" : {
25
26
"include" : [
26
- " @magic-sdk/commons "
27
+ " @magic-sdk/provider "
27
28
]
28
29
},
29
30
"devDependencies" : {
30
- "@magic-sdk/commons" : " ^17.2.0"
31
+ "@magic-sdk/provider" : " ^21.2.0" ,
32
+ "@polkadot/types" : " ^10.10.1" ,
33
+ "@polkadot/util" : " ^12.5.1"
34
+ },
35
+ "dependencies" : {
36
+ "@polkadot/api" : " ^10.10.1"
37
+ },
38
+ "peerDependencies" : {
39
+ "@polkadot/api" : " ^10.10.1"
31
40
}
32
41
}
Original file line number Diff line number Diff line change 1
- import { Extension } from '@magic-sdk/commons' ;
2
- import { PolkadotConfig , ConfigType } from './type' ;
1
+ import { Extension } from '@magic-sdk/provider' ;
2
+ import type { ConfigType , PolkadotConfig } from './type' ;
3
+
4
+ export { MagicSigner } from './magic-signer' ;
3
5
4
6
export class PolkadotExtension extends Extension . Internal < 'polkadot' , PolkadotConfig > {
5
7
name = 'polkadot' as const ;
Original file line number Diff line number Diff line change
1
+ import type { Signer } from '@polkadot/api/types' ;
2
+ import type { ISubmittableResult , SignerPayloadJSON , SignerPayloadRaw } from '@polkadot/types/types' ;
3
+ import type { HexString } from '@polkadot/util/types' ;
4
+ import type { H256 } from '@polkadot/types/interfaces' ;
5
+ import { Extension , InstanceWithExtensions , SDKBase } from '@magic-sdk/provider' ;
6
+ import { PolkadotExtension } from '.' ;
7
+
8
+ type MagicInstnace = InstanceWithExtensions < SDKBase , [ PolkadotExtension , ...Extension [ ] ] > ;
9
+
10
+ export class MagicSigner implements Signer {
11
+ private magic : MagicInstnace ;
12
+ private nextId = 0 ;
13
+
14
+ constructor ( magic : MagicInstnace ) {
15
+ this . magic = magic ;
16
+ }
17
+
18
+ /**
19
+ * @description signs an extrinsic payload from a serialized form
20
+ */
21
+ signPayload = async ( payload : SignerPayloadJSON ) => {
22
+ const signature = await this . magic . rpcProvider . send < string > ( 'pdt_signPayload' , [ payload ] ) ;
23
+
24
+ return {
25
+ id : this . nextId ++ ,
26
+ signature : signature as HexString ,
27
+ } ;
28
+ } ;
29
+ /**
30
+ * @description signs a raw payload, only the bytes data as supplied
31
+ */
32
+ signRaw = async ( raw : SignerPayloadRaw ) => {
33
+ const signature = await this . magic . rpcProvider . send < HexString > ( 'pdt_signRaw' , [ raw ] ) ;
34
+
35
+ return {
36
+ id : this . nextId ++ ,
37
+ signature,
38
+ } ;
39
+ } ;
40
+
41
+ /**
42
+ * @description Receives an update for the extrinsic signed by a `signer.sign`
43
+ */
44
+ update ?: ( id : number , status : H256 | ISubmittableResult ) => void ;
45
+ }
You can’t perform that action at this time.
0 commit comments