Skip to content

Commit 3adf8f6

Browse files
authored
Merge pull request #65 from cruxprotocol/feature/keypair-injection-configservice-refactor
add pending registrations call and refactoring of configService
2 parents e9424b4 + 8eec1d6 commit 3adf8f6

File tree

16 files changed

+619
-344
lines changed

16 files changed

+619
-344
lines changed

README.md

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ To initialize the sdk, you need to minimally pass a javascript object with follo
2323
2. BNS(BlockStack Name Service) Node
2424
3. Currency symbol map of your wallet
2525
- To help you get started, you can use `cruxdev` as the value which is already configured for our dev test users. It has 5 pre-registered crypto symbols for a fast start. You can contact us at [telegram](https://t.me/cruxpay_integration) channel for registration of your own walletClientName.
26+
3. **privateKey (optional)**
27+
- Required to re-initialise the CruxClient with same user across different devices.
28+
- For clients using HD derivation paths, recommended to use the path (`m/889'/0/0'`) for CruxPay keypair node derivation with respect to account indices.
2629

2730
`**Note:** Cruxprotocol JS SDK is case insensetive for cryptocurrency symbols and will always output lowercase symbols.`
2831

@@ -37,7 +40,8 @@ function getPassHashedEncryptionKey() {
3740

3841
let cruxClientOptions = {
3942
getEncryptionKey: getPassHashedEncryptionKey,
40-
walletClientName: 'cruxdev'
43+
walletClientName: 'cruxdev',
44+
privateKey: "6bd397dc89272e71165a0e7d197b280c7a88ed5b1e44e1928c25455506f1968f" // (optional parameter)
4145
}
4246

4347
let cruxClient = new CruxClient(cruxClientOptions);
@@ -69,17 +73,39 @@ Refer [error-handling.md](https://github.com/cruxprotocol/js-sdk/blob/master/err
6973
- subdomain part of [CruxID](#cruxid)
7074
- Returns: Promise resolving to a _boolean_ indicating whether a particular Crux ID is available for registration.
7175

72-
2. ##### getAssetMapping()
76+
2. ##### getAssetMap()
7377
- Description: Get Wallet's asset map with currency symbols as the keys and asset object as the value.
7478
- Params: None
7579
- Returns: [IResolvedClientAssetMapping](#iresolvedclientassetmapping) which has symbols and asset objects.
7680

7781
3. ##### registerCruxID(cruxID<onlySubdomain>)
78-
- Description: Reserves/registers the cruxID for the user. The user can link any blockchain address to his CruxID with the help of newAddressMap sent. The addresses are now publicly linked and can be resolved.
79-
- Note: To get which currencies can be part of newAddressMap please call `getAssetMapping()`.
82+
- Description: Reserves/registers the cruxID for the user. The user can link any blockchain address to his CruxID immediately after registration using [putAddressMap](#putaddressmap).
8083
- Params:
8184
- subdomain part of [CruxID](#cruxid)
8285
- Returns: Promise resolving on successful call to the registrar.
86+
```javascript
87+
const sampleAddressMap: IAddressMapping = {
88+
'BTC': {
89+
addressHash: '1F1tAaz5x1HUXrCNLbtMDqcw6o5GNn4xqX'
90+
},
91+
'ETH': {
92+
addressHash: '0x7cB57B5A97eAbe94205C07890BE4c1aD31E486A8'
93+
},
94+
}
95+
96+
// Advised to pipe the method putAddressMap to registerCruxID call
97+
98+
await cruxClient.registerCruxID("bob")
99+
.then(() => {
100+
return cruxClient.putAddressMap(sampleAddressMap)
101+
.catch((addressUpdationError) => {
102+
// Handling addressUpdation error
103+
})
104+
})
105+
.catch((registrationError) => {
106+
// Handling registration error
107+
})
108+
```
83109

84110
4. ##### resolveCurrencyAddressForCruxID(cruxID, walletCurrencySymbol)
85111
- Description: Helps to lookup a mapped address for a currency of any CruxID if its marked publically accessible.
@@ -95,9 +121,9 @@ Refer [error-handling.md](https://github.com/cruxprotocol/js-sdk/blob/master/err
95121

96122
6. ##### putAddressMap(newAddressMap)
97123
- Description: Helps to update 2 things:-
98-
- change list of publicly accessible currency addresses.
124+
- publish/change list of publicly accessible currency addresses.
99125
- change the value of addressHash and/or secIdentifier to another one.
100-
- Note: To get which currencies can be part of newAddressMap please call `getAssetMapping()`.
126+
- Note: The addresses are now publicly linked and can be resolved. To get which currencies can be part of newAddressMap please call `getAssetMapping()`.
101127
- Params:
102128
- newAddressMap of type [IAddressMapping](#iaddressmapping) has modified map has symbols and addresses a user wants to publically expose with CruxID.
103129
- Returns: Promise resolving to {success: [IPutAddressMapSuccess](#iputaddressmapSuccess), failures: [IPutAddressMapFailures](#iputaddressmapfailures)}

error-handling.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ Some common ERROR_CODES thrown by the SDK:
7676
BlockstackIdInvalidSubdomainForTranslation = 4009,
7777
BlockstackIdInvalidDomainForTranslation = 4010,
7878
CurrencyDoesNotExistInClientMapping = 4011,
79+
ExistingCruxIDFound = 4012,
80+
CruxIDUnavailable = 4013,
7981
}
8082
```
8183

0 commit comments

Comments
 (0)