Skip to content

Commit bb33f8f

Browse files
authored
Merge pull request #223 from onflow/stable-cadence
Stable cadence
2 parents 2959756 + da55d0a commit bb33f8f

37 files changed

Lines changed: 2424 additions & 1060 deletions

.env.development

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
# We recommend to use the service account defined in the flow.json file your emulator is using.
44

55
FLOW_INIT_ACCOUNTS=0
6-
CONTRACT_FUNGIBLE_TOKEN=0xee82856bf20e2aa6
7-
CONTRACT_FLOW_TOKEN=0x0ae53cb6e3f42a79
8-
CONTRACT_FUSD=0xf8d6e0586b0a20c7
9-
CONTRACT_FCL_CRYPTO=0xf8d6e0586b0a20c7
106
FLOW_AVATAR_URL=https://avatars.onflow.org/avatar/
117

128
# EMULATOR REST API ENDPOINT

.env.example

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
# We recommend to use the service account definied in the flow.json file your emulator is using.
44

55
FLOW_INIT_ACCOUNTS=0
6-
CONTRACT_FUNGIBLE_TOKEN=0xee82856bf20e2aa6
7-
CONTRACT_FLOW_TOKEN=0x0ae53cb6e3f42a79
8-
CONTRACT_FUSD=0xf8d6e0586b0a20c7
9-
CONTRACT_FCL_CRYPTO=0xf8d6e0586b0a20c7
106
FLOW_AVATAR_URL=https://avatars.onflow.org/avatar/
117

128
# EMULATOR REST API ENDPOINT

cadence/contracts/FCL.cdc

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
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

cadence/contracts/FCLCrypto.cdc

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1-
pub contract FCLCrypto {
2-
3-
pub fun verifyUserSignatures(
1+
/*
2+
FCLCrypto
3+
4+
The FCLCrypto contract provides functions which allow to verify signatures and check for signing power.
5+
*/
6+
7+
access(all) contract FCLCrypto {
8+
9+
/// verifyUserSignatures allows to verify the user signatures for the given account.
10+
///
11+
/// @param address: The address of the account
12+
/// @param message: The signed data
13+
/// @param keyIndices: This integer array maps the signatures to the account keys by index
14+
/// @param signatures: The signatures belonging to the account keys
15+
///
16+
/// @return Whether all signatures are valid and the combined total key weight reaches signing power
17+
///
18+
access(all) fun verifyUserSignatures(
419
address: Address,
520
message: String,
621
keyIndices: [Int],
@@ -15,7 +30,16 @@ pub contract FCLCrypto {
1530
)
1631
}
1732

18-
pub fun verifyAccountProofSignatures(
33+
/// verifyAccountProofSignatures allows to verify the account proof signatures for the given account.
34+
///
35+
/// @param address: The address of the account
36+
/// @param message: The signed data
37+
/// @param keyIndices: This integer array maps the signatures to the account keys by index
38+
/// @param signatures: The signatures belonging to the account keys
39+
///
40+
/// @return Whether all signatures are valid and the combined total key weight reaches signing power
41+
///
42+
access(all) fun verifyAccountProofSignatures(
1943
address: Address,
2044
message: String,
2145
keyIndices: [Int],
@@ -37,7 +61,18 @@ pub contract FCLCrypto {
3761
)
3862
}
3963

40-
priv fun verifySignatures(
64+
/// verifySignatures is a private function which provides the functionality to verify
65+
/// signatures for the public functions.
66+
///
67+
/// @param address: The address of the account
68+
/// @param message: The signed data
69+
/// @param keyIndices: This integer array maps the signatures to the account keys by index
70+
/// @param signatures: The signatures belonging to the account keys
71+
/// @param domainSeparationTag: The domain tag originally used for the signatures
72+
///
73+
/// @return Whether all signatures are valid and the combined total key weight reaches signing power
74+
///
75+
access(self) fun verifySignatures(
4176
address: Address,
4277
message: String,
4378
keyIndices: [Int],
@@ -96,9 +131,9 @@ pub contract FCLCrypto {
96131
return totalWeight >= 1000.0
97132
}
98133

99-
priv let domainSeparationTagFlowUser: String
100-
priv let domainSeparationTagFCLUser: String
101-
priv let domainSeparationTagAccountProof: String
134+
access(self) let domainSeparationTagFlowUser: String
135+
access(self) let domainSeparationTagFCLUser: String
136+
access(self) let domainSeparationTagAccountProof: String
102137

103138
init() {
104139
self.domainSeparationTagFlowUser = "FLOW-V0.0-user"

0 commit comments

Comments
 (0)