1- pub contract FCL {
2- pub let storagePath : StoragePath
1+ access ( all ) contract FCL {
2+ access ( all ) let storagePath : StoragePath
33
4- pub struct Account {
5- pub let type : String
6- pub let address : Address
7- pub let keyId : Int
8- pub var label : String
9- pub var scopes : [String ]
4+ access (all ) struct FCLKey {
5+ access (all ) let publicKey : [UInt8 ]
6+ access (all ) let signatureAlgorithm : UInt8
7+ access (all ) let hashAlgorithm : UInt8
8+
9+ init (publicKey : [UInt8 ], signatureAlgorithm : UInt8 , hashAlgorithm : UInt8 ) {
10+ self .publicKey = publicKey
11+ self .signatureAlgorithm = signatureAlgorithm
12+ self .hashAlgorithm = hashAlgorithm
13+ }
14+ }
15+
16+ access (all ) struct FCLAccount {
17+ access (all ) let type : String
18+ access (all ) let address : Address
19+ access (all ) let keyId : Int
20+ access (all ) var label : String
21+ access (all ) var scopes : [String ]
1022
1123 init (address : Address , label : String , scopes : [String ]) {
1224 self .type = " ACCOUNT"
@@ -16,59 +28,74 @@ pub contract FCL {
1628 self .scopes = scopes
1729 }
1830
19- pub fun update (label : String , scopes : [String ]) {
31+ access ( all ) fun update (label : String , scopes : [String ]) {
2032 self .label = label
2133 self .scopes = scopes
2234 }
2335 }
2436
25- pub resource Root {
26- pub let key : [ UInt8 ]
27- pub let accounts : {Address : Account }
37+ access ( all ) resource Root {
38+ access ( all ) let key : FCLKey
39+ access ( all ) let accounts : {Address : FCLAccount }
2840
29- init (_ key : String ) {
30- self .key = key . decodeHex ()
41+ init (_ key : FCLKey ) {
42+ self .key = key
3143 self .accounts = {}
3244 }
3345
34- pub fun add (_ acct : Account ) {
46+ access ( all ) fun add (_ acct : FCLAccount ) {
3547 self .accounts [acct .address ] = acct
3648 }
3749
38- pub fun update (address : Address , label : String , scopes : [String ]) {
50+ access ( all ) fun update (address : Address , label : String , scopes : [String ]) {
3951 let acct = self .accounts [address ]
4052 acct ! .update (label : label , scopes : scopes )
4153 self .accounts [address ] = acct
4254 }
4355 }
4456
45- pub fun accounts (): {Address : Account } {
46- return self .account .borrow <&Root >(from : self .storagePath )! .accounts
57+ access ( all ) fun accounts (): & {Address : FCLAccount } {
58+ return self .account .storage . borrow <&Root >(from : self .storagePath )! .accounts
4759 }
4860
49- pub fun getServiceKey (): [ UInt8 ] {
50- return self .account .borrow <&Root >(from : self .storagePath )! .key
61+ access ( all ) fun getServiceKey (): & FCLKey {
62+ return self .account .storage . borrow <&Root >(from : self .storagePath )! .key
5163 }
5264
53- pub fun new (label : String , scopes : [String ], address : Address ? ): AuthAccount {
54- let acct = AuthAccount (payer : self .account )
55- acct .addPublicKey (self .getServiceKey ())
65+ access (all ) fun new (label : String , scopes : [String ], address : Address ? ): &Account {
66+ let acct = Account (payer : self .account )
67+ let key = self .getServiceKey ()
68+
69+ acct .keys .add (
70+ publicKey : PublicKey (
71+ publicKey : key .publicKey .map (fun (_ byte : UInt8 ): UInt8 {
72+ return byte
73+ }),
74+ signatureAlgorithm : SignatureAlgorithm (key .signatureAlgorithm )! ,
75+ ),
76+ hashAlgorithm : HashAlgorithm (key .hashAlgorithm )! ,
77+ weight : 1000.0
78+ )
5679
5780 self .account
81+ .storage
5882 .borrow <&Root >(from : self .storagePath )!
59- .add (Account (address : address ?? acct .address , label : label , scopes : scopes ))
83+ .add (FCLAccount (address : address ?? acct .address , label : label , scopes : scopes ))
6084
6185 return acct
6286 }
6387
64- pub fun update (address : Address , label : String , scopes : [String ]) {
65- self .account .borrow <&Root >(from : self .storagePath )!
88+ access ( all ) fun update (address : Address , label : String , scopes : [String ]) {
89+ self .account .storage . borrow <&Root >(from : self .storagePath )!
6690 .update (address : address , label : label , scopes : scopes )
6791 }
6892
69- init (key : String , initAccountsLabels : [String ]) {
93+ init (publicKey : String , hashAlgorithm : UInt8 , signAlgorithm : UInt8 , initAccountsLabels : [String ]) {
94+ let keyByteArray = publicKey .decodeHex ()
95+ let key = FCLKey (publicKey : keyByteArray , signatureAlgorithm : signAlgorithm , hashAlgorithm : hashAlgorithm )
96+
7097 self .storagePath = /storage/FCL_DEV_WALLET
71- self .account .save (<- create Root (key ), to : self .storagePath )
98+ self .account .storage . save (<- create Root (key ), to : self .storagePath )
7299
73100 self .new (label : initAccountsLabels [0 ], scopes : [], address : self .account .address )
74101 var acctInitIndex = 1
0 commit comments