Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update @celo/utils to allow AccountAuthResponseSuccess to include pepper #7546

Merged
merged 10 commits into from
Mar 31, 2021
24 changes: 23 additions & 1 deletion packages/docs/developer-resources/dappkit/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ login = async () => {

const dappkitResponse = await waitForAccountAuth(requestId);

this.setState({ address: dappkitResponse.address, phoneNumber: dappkitResponse.phoneNumber });
// The pepper is not available in all Valora versions
this.setState({ address: dappkitResponse.address, phoneNumber: dappkitResponse.phoneNumber, pepper: dappkitResponse.pepper });
}
```

Expand Down Expand Up @@ -69,6 +70,27 @@ let cUSDBalance = cUSDBalanceBig.toString();
this.setState({ cUSDBalance, isLoadingBalance: false });
```

## Checking attestations for the phone number

If the user is using a Valora version that passes the `pepper` that Valora has for a `phone_number`, you can use both pieces of information to determine attestations for the identifier (learn more about the [lightweight identity protocol here](../../celo-codebase/protocol/identity)):

```javascript
import { PhoneNumberUtils } from '@celo/utils'
const attestations = await kit.contracts.getAttestations();

const identifier = PhoneNumberUtils.getPhoneHash(dappkitResponse.phoneNumber, dappkitResponse.pepper);

// Find all accounts that have received attestations for this phone number
const accounts = attestations.lookupAccountsForIdentifier(identifier);

// Get the attestations stats for the accounts
for (const account of accounts) {
const stat = await attestations.getAttestationStat(identifier, account);
console.log(`Total: ${stat.total}, Completed: ${stat.completed}`);
}

```

## Signing Transactions

Let's go from accessing account information to submitting transactions. To alter state on the blockchain, you need to make a transaction object with your smart contract or any of the Celo Core Contracts in ContractKit. All that is left to do is to pass the transaction object to DAppKit.
Expand Down
5 changes: 4 additions & 1 deletion packages/sdk/utils/src/dappkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@ export interface AccountAuthResponseSuccess {
status: DappKitResponseStatus.SUCCESS
address: string
phoneNumber: string
pepper: string | undefined
}

export const AccountAuthResponseSuccess = (
address: string,
phoneNumber: string
phoneNumber: string,
pepper: string | undefined
): AccountAuthResponseSuccess => ({
type: DappKitRequestTypes.ACCOUNT_ADDRESS,
status: DappKitResponseStatus.SUCCESS,
address,
phoneNumber,
pepper,
})

export interface AccountAuthResponseFailure {
Expand Down