diff --git a/.changeset/rude-parrots-know.md b/.changeset/rude-parrots-know.md new file mode 100644 index 000000000..020097fa3 --- /dev/null +++ b/.changeset/rude-parrots-know.md @@ -0,0 +1,17 @@ +--- +'@celo/base': major +'@celo/utils': major +--- + +remove deprecated functions and consts exported from ./contacts and ./displayformating. ./currencies and ./phonenumbers. If these are used by your app we recommend to inline the functions from the previous release. + +* https://github.com/celo-org/developer-tooling/blob/%40celo/wallet-base%406.0.1/packages/sdk/base/src/contacts.ts +* https://github.com/celo-org/developer-tooling/blob/%40celo/wallet-base%406.0.1/packages/sdk/base/src/displayFormatting.ts +* https://github.com/celo-org/developer-tooling/blob/%40celo/wallet-base%406.0.1/packages/sdk/base/src/phoneNumbers.ts + +https://github.com/celo-org/developer-tooling/tree/%40celo/wallet-base%406.0.1/packages/sdk/base/src + +Full List of removed exports -- ContactPhoneNumber, MinimalContact, getContactPhoneNumber, isContact, CURRENCY_ENUM, Currency, CURRENCIES, resolveCurrency, SHORT_CURRENCIES, currencyToShortMap | getErrorMessage | anonymizedPhone | getContactNameHash + + + diff --git a/docs/sdk/base/README.md b/docs/sdk/base/README.md index c6e67fab7..a45aff521 100644 --- a/docs/sdk/base/README.md +++ b/docs/sdk/base/README.md @@ -10,9 +10,7 @@ - [address](modules/address.md) - [async](modules/async.md) - [collections](modules/collections.md) -- [contacts](modules/contacts.md) - [currencies](modules/currencies.md) -- [displayFormatting](modules/displayFormatting.md) - [future](modules/future.md) - [index](modules/index.md) - [inputValidation](modules/inputValidation.md) diff --git a/docs/sdk/base/enums/currencies.CURRENCY_ENUM.md b/docs/sdk/base/enums/currencies.CURRENCY_ENUM.md deleted file mode 100644 index f94a1f982..000000000 --- a/docs/sdk/base/enums/currencies.CURRENCY_ENUM.md +++ /dev/null @@ -1,47 +0,0 @@ -[@celo/base](../README.md) / [currencies](../modules/currencies.md) / CURRENCY\_ENUM - -# Enumeration: CURRENCY\_ENUM - -[currencies](../modules/currencies.md).CURRENCY_ENUM - -**`Deprecated`** - -use StableToken and Token - -## Table of contents - -### Enumeration Members - -- [DOLLAR](currencies.CURRENCY_ENUM.md#dollar) -- [EURO](currencies.CURRENCY_ENUM.md#euro) -- [GOLD](currencies.CURRENCY_ENUM.md#gold) - -## Enumeration Members - -### DOLLAR - -• **DOLLAR** = ``"Celo Dollar"`` - -#### Defined in - -[packages/sdk/base/src/currencies.ts:4](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/currencies.ts#L4) - -___ - -### EURO - -• **EURO** = ``"Celo Euro"`` - -#### Defined in - -[packages/sdk/base/src/currencies.ts:5](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/currencies.ts#L5) - -___ - -### GOLD - -• **GOLD** = ``"Celo Gold"`` - -#### Defined in - -[packages/sdk/base/src/currencies.ts:3](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/currencies.ts#L3) diff --git a/docs/sdk/base/enums/currencies.SHORT_CURRENCIES.md b/docs/sdk/base/enums/currencies.SHORT_CURRENCIES.md deleted file mode 100644 index e2420c530..000000000 --- a/docs/sdk/base/enums/currencies.SHORT_CURRENCIES.md +++ /dev/null @@ -1,47 +0,0 @@ -[@celo/base](../README.md) / [currencies](../modules/currencies.md) / SHORT\_CURRENCIES - -# Enumeration: SHORT\_CURRENCIES - -[currencies](../modules/currencies.md).SHORT_CURRENCIES - -**`Deprecated`** - -use StableToken and Token - -## Table of contents - -### Enumeration Members - -- [DOLLAR](currencies.SHORT_CURRENCIES.md#dollar) -- [EURO](currencies.SHORT_CURRENCIES.md#euro) -- [GOLD](currencies.SHORT_CURRENCIES.md#gold) - -## Enumeration Members - -### DOLLAR - -• **DOLLAR** = ``"dollar"`` - -#### Defined in - -[packages/sdk/base/src/currencies.ts:62](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/currencies.ts#L62) - -___ - -### EURO - -• **EURO** = ``"euro"`` - -#### Defined in - -[packages/sdk/base/src/currencies.ts:64](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/currencies.ts#L64) - -___ - -### GOLD - -• **GOLD** = ``"gold"`` - -#### Defined in - -[packages/sdk/base/src/currencies.ts:63](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/currencies.ts#L63) diff --git a/docs/sdk/base/enums/currencies.StableToken.md b/docs/sdk/base/enums/currencies.StableToken.md index 5f0ad0623..b6036ab4a 100644 --- a/docs/sdk/base/enums/currencies.StableToken.md +++ b/docs/sdk/base/enums/currencies.StableToken.md @@ -20,7 +20,7 @@ #### Defined in -[packages/sdk/base/src/currencies.ts:10](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/currencies.ts#L10) +[packages/sdk/base/src/currencies.ts:3](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/currencies.ts#L3) ___ @@ -30,7 +30,7 @@ ___ #### Defined in -[packages/sdk/base/src/currencies.ts:11](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/currencies.ts#L11) +[packages/sdk/base/src/currencies.ts:4](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/currencies.ts#L4) ___ @@ -40,4 +40,4 @@ ___ #### Defined in -[packages/sdk/base/src/currencies.ts:9](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/currencies.ts#L9) +[packages/sdk/base/src/currencies.ts:2](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/currencies.ts#L2) diff --git a/docs/sdk/base/enums/currencies.Token.md b/docs/sdk/base/enums/currencies.Token.md index 7b9fe81a3..ae8b7f8f8 100644 --- a/docs/sdk/base/enums/currencies.Token.md +++ b/docs/sdk/base/enums/currencies.Token.md @@ -18,4 +18,4 @@ #### Defined in -[packages/sdk/base/src/currencies.ts:15](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/currencies.ts#L15) +[packages/sdk/base/src/currencies.ts:8](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/currencies.ts#L8) diff --git a/docs/sdk/base/interfaces/contacts.ContactPhoneNumber.md b/docs/sdk/base/interfaces/contacts.ContactPhoneNumber.md deleted file mode 100644 index ca2a19a58..000000000 --- a/docs/sdk/base/interfaces/contacts.ContactPhoneNumber.md +++ /dev/null @@ -1,32 +0,0 @@ -[@celo/base](../README.md) / [contacts](../modules/contacts.md) / ContactPhoneNumber - -# Interface: ContactPhoneNumber - -[contacts](../modules/contacts.md).ContactPhoneNumber - -## Table of contents - -### Properties - -- [label](contacts.ContactPhoneNumber.md#label) -- [number](contacts.ContactPhoneNumber.md#number) - -## Properties - -### label - -• `Optional` **label**: `string` - -#### Defined in - -[packages/sdk/base/src/contacts.ts:2](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/contacts.ts#L2) - -___ - -### number - -• `Optional` **number**: `string` - -#### Defined in - -[packages/sdk/base/src/contacts.ts:3](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/contacts.ts#L3) diff --git a/docs/sdk/base/interfaces/contacts.MinimalContact.md b/docs/sdk/base/interfaces/contacts.MinimalContact.md deleted file mode 100644 index ed39fccc1..000000000 --- a/docs/sdk/base/interfaces/contacts.MinimalContact.md +++ /dev/null @@ -1,54 +0,0 @@ -[@celo/base](../README.md) / [contacts](../modules/contacts.md) / MinimalContact - -# Interface: MinimalContact - -[contacts](../modules/contacts.md).MinimalContact - -## Table of contents - -### Properties - -- [displayName](contacts.MinimalContact.md#displayname) -- [phoneNumbers](contacts.MinimalContact.md#phonenumbers) -- [recordID](contacts.MinimalContact.md#recordid) -- [thumbnailPath](contacts.MinimalContact.md#thumbnailpath) - -## Properties - -### displayName - -• `Optional` **displayName**: `string` - -#### Defined in - -[packages/sdk/base/src/contacts.ts:8](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/contacts.ts#L8) - -___ - -### phoneNumbers - -• `Optional` **phoneNumbers**: [`ContactPhoneNumber`](contacts.ContactPhoneNumber.md)[] - -#### Defined in - -[packages/sdk/base/src/contacts.ts:9](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/contacts.ts#L9) - -___ - -### recordID - -• **recordID**: `string` - -#### Defined in - -[packages/sdk/base/src/contacts.ts:7](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/contacts.ts#L7) - -___ - -### thumbnailPath - -• `Optional` **thumbnailPath**: `string` - -#### Defined in - -[packages/sdk/base/src/contacts.ts:10](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/contacts.ts#L10) diff --git a/docs/sdk/base/modules/contacts.md b/docs/sdk/base/modules/contacts.md deleted file mode 100644 index f1b1a27ee..000000000 --- a/docs/sdk/base/modules/contacts.md +++ /dev/null @@ -1,55 +0,0 @@ -[@celo/base](../README.md) / contacts - -# Module: contacts - -## Table of contents - -### Interfaces - -- [ContactPhoneNumber](../interfaces/contacts.ContactPhoneNumber.md) -- [MinimalContact](../interfaces/contacts.MinimalContact.md) - -### Functions - -- [getContactPhoneNumber](contacts.md#getcontactphonenumber) -- [isContact](contacts.md#iscontact) - -## Functions - -### getContactPhoneNumber - -▸ **getContactPhoneNumber**(`contact`): `undefined` \| ``null`` \| `string` - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `contact` | [`MinimalContact`](../interfaces/contacts.MinimalContact.md) | - -#### Returns - -`undefined` \| ``null`` \| `string` - -#### Defined in - -[packages/sdk/base/src/contacts.ts:13](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/contacts.ts#L13) - -___ - -### isContact - -▸ **isContact**(`contactOrNumber`): contactOrNumber is MinimalContact - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `contactOrNumber` | `any` | - -#### Returns - -contactOrNumber is MinimalContact - -#### Defined in - -[packages/sdk/base/src/contacts.ts:26](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/contacts.ts#L26) diff --git a/docs/sdk/base/modules/currencies.md b/docs/sdk/base/modules/currencies.md index cd1492d68..5b8e00c36 100644 --- a/docs/sdk/base/modules/currencies.md +++ b/docs/sdk/base/modules/currencies.md @@ -6,8 +6,6 @@ ### Enumerations -- [CURRENCY\_ENUM](../enums/currencies.CURRENCY_ENUM.md) -- [SHORT\_CURRENCIES](../enums/currencies.SHORT_CURRENCIES.md) - [StableToken](../enums/currencies.StableToken.md) - [Token](../enums/currencies.Token.md) @@ -15,15 +13,6 @@ - [CeloTokenType](currencies.md#celotokentype) -### Variables - -- [CURRENCIES](currencies.md#currencies) -- [currencyToShortMap](currencies.md#currencytoshortmap) - -### Functions - -- [resolveCurrency](currencies.md#resolvecurrency) - ## Type Aliases ### CeloTokenType @@ -32,58 +21,4 @@ #### Defined in -[packages/sdk/base/src/currencies.ts:18](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/currencies.ts#L18) - -## Variables - -### CURRENCIES - -• `Const` **CURRENCIES**: `CurrencyObject` - -**`Deprecated`** - -#### Defined in - -[packages/sdk/base/src/currencies.ts:29](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/currencies.ts#L29) - -___ - -### currencyToShortMap - -• `Const` **currencyToShortMap**: `Object` - -**`Deprecated`** - -use StableToken and Token - -#### Type declaration - -| Name | Type | -| :------ | :------ | -| `Celo Dollar` | [`SHORT_CURRENCIES`](../enums/currencies.SHORT_CURRENCIES.md) | -| `Celo Euro` | [`SHORT_CURRENCIES`](../enums/currencies.SHORT_CURRENCIES.md) | -| `Celo Gold` | [`SHORT_CURRENCIES`](../enums/currencies.SHORT_CURRENCIES.md) | - -#### Defined in - -[packages/sdk/base/src/currencies.ts:68](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/currencies.ts#L68) - -## Functions - -### resolveCurrency - -▸ **resolveCurrency**(`label`): [`CURRENCY_ENUM`](../enums/currencies.CURRENCY_ENUM.md) - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `label` | `string` | - -#### Returns - -[`CURRENCY_ENUM`](../enums/currencies.CURRENCY_ENUM.md) - -#### Defined in - -[packages/sdk/base/src/currencies.ts:47](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/currencies.ts#L47) +[packages/sdk/base/src/currencies.ts:11](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/currencies.ts#L11) diff --git a/docs/sdk/base/modules/displayFormatting.md b/docs/sdk/base/modules/displayFormatting.md deleted file mode 100644 index a93b52739..000000000 --- a/docs/sdk/base/modules/displayFormatting.md +++ /dev/null @@ -1,29 +0,0 @@ -[@celo/base](../README.md) / displayFormatting - -# Module: displayFormatting - -## Table of contents - -### Functions - -- [getErrorMessage](displayFormatting.md#geterrormessage) - -## Functions - -### getErrorMessage - -▸ **getErrorMessage**(`error`): `string` - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `error` | `Error` | - -#### Returns - -`string` - -#### Defined in - -[packages/sdk/base/src/displayFormatting.ts:2](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/displayFormatting.ts#L2) diff --git a/docs/sdk/base/modules/index.md b/docs/sdk/base/modules/index.md index 07cba7790..9fe9db168 100644 --- a/docs/sdk/base/modules/index.md +++ b/docs/sdk/base/modules/index.md @@ -12,18 +12,14 @@ - [BaseProps](index.md#baseprops) - [Bip39](index.md#bip39) - [CELO\_DERIVATION\_PATH\_BASE](index.md#celo_derivation_path_base) -- [CURRENCIES](index.md#currencies) -- [CURRENCY\_ENUM](index.md#currency_enum) - [CeloTokenType](index.md#celotokentype) - [Comparator](index.md#comparator) -- [ContactPhoneNumber](index.md#contactphonenumber) - [Err](index.md#err) - [ErrorResult](index.md#errorresult) - [Future](index.md#future) - [JSONParseError](index.md#jsonparseerror) - [JSONParseErrorType](index.md#jsonparseerrortype) - [Logger](index.md#logger) -- [MinimalContact](index.md#minimalcontact) - [MnemonicLanguages](index.md#mnemoniclanguages) - [MnemonicStrength](index.md#mnemonicstrength) - [NULL\_ADDRESS](index.md#null_address) @@ -40,7 +36,6 @@ - [RootError](index.md#rooterror) - [RunningTask](index.md#runningtask) - [RunningTaskWithValue](index.md#runningtaskwithvalue) -- [SHORT\_CURRENCIES](index.md#short_currencies) - [Signature](index.md#signature) - [SignatureBase](index.md#signaturebase) - [Signer](index.md#signer) @@ -51,23 +46,18 @@ - [Token](index.md#token) - [URL\_REGEX](index.md#url_regex) - [ValidatorKind](index.md#validatorkind) -- [anonymizedPhone](index.md#anonymizedphone) - [appendPath](index.md#appendpath) - [bufferToHex](index.md#buffertohex) - [concurrentMap](index.md#concurrentmap) - [concurrentValuesMap](index.md#concurrentvaluesmap) - [conditionWatcher](index.md#conditionwatcher) - [consoleLogger](index.md#consolelogger) -- [currencyToShortMap](index.md#currencytoshortmap) - [ensureLeading0x](index.md#ensureleading0x) - [eqAddress](index.md#eqaddress) - [findAddressIndex](index.md#findaddressindex) - [getAddressChunks](index.md#getaddresschunks) -- [getContactPhoneNumber](index.md#getcontactphonenumber) -- [getErrorMessage](index.md#geterrormessage) - [hexToBuffer](index.md#hextobuffer) - [intersection](index.md#intersection) -- [isContact](index.md#iscontact) - [isE164Number](index.md#ise164number) - [isErr](index.md#iserr) - [isHexString](index.md#ishexstring) @@ -90,7 +80,6 @@ - [pipeToFuture](index.md#pipetofuture) - [prefixLogger](index.md#prefixlogger) - [repeatTask](index.md#repeattask) -- [resolveCurrency](index.md#resolvecurrency) - [retryAsync](index.md#retryasync) - [retryAsyncWithBackOff](index.md#retryasyncwithbackoff) - [retryAsyncWithBackOffAndTimeout](index.md#retryasyncwithbackoffandtimeout) @@ -147,18 +136,6 @@ Re-exports [CELO_DERIVATION_PATH_BASE](account.md#celo_derivation_path_base) ___ -### CURRENCIES - -Re-exports [CURRENCIES](currencies.md#currencies) - -___ - -### CURRENCY\_ENUM - -Re-exports [CURRENCY_ENUM](../enums/currencies.CURRENCY_ENUM.md) - -___ - ### CeloTokenType Re-exports [CeloTokenType](currencies.md#celotokentype) @@ -171,12 +148,6 @@ Re-exports [Comparator](collections.md#comparator) ___ -### ContactPhoneNumber - -Re-exports [ContactPhoneNumber](../interfaces/contacts.ContactPhoneNumber.md) - -___ - ### Err Re-exports [Err](result.md#err) @@ -213,12 +184,6 @@ Re-exports [Logger](logger.md#logger) ___ -### MinimalContact - -Re-exports [MinimalContact](../interfaces/contacts.MinimalContact.md) - -___ - ### MnemonicLanguages Re-exports [MnemonicLanguages](../enums/account.MnemonicLanguages.md) @@ -315,12 +280,6 @@ Re-exports [RunningTaskWithValue](../interfaces/task.RunningTaskWithValue.md) ___ -### SHORT\_CURRENCIES - -Re-exports [SHORT_CURRENCIES](../enums/currencies.SHORT_CURRENCIES.md) - -___ - ### Signature Re-exports [Signature](../interfaces/signatureUtils.Signature.md) @@ -381,12 +340,6 @@ Re-exports [ValidatorKind](../enums/inputValidation.ValidatorKind.md) ___ -### anonymizedPhone - -Re-exports [anonymizedPhone](phoneNumbers.md#anonymizedphone) - -___ - ### appendPath Re-exports [appendPath](string.md#appendpath) @@ -423,12 +376,6 @@ Re-exports [consoleLogger](logger.md#consolelogger) ___ -### currencyToShortMap - -Re-exports [currencyToShortMap](currencies.md#currencytoshortmap) - -___ - ### ensureLeading0x Re-exports [ensureLeading0x](address.md#ensureleading0x) @@ -453,18 +400,6 @@ Re-exports [getAddressChunks](address.md#getaddresschunks) ___ -### getContactPhoneNumber - -Re-exports [getContactPhoneNumber](contacts.md#getcontactphonenumber) - -___ - -### getErrorMessage - -Re-exports [getErrorMessage](displayFormatting.md#geterrormessage) - -___ - ### hexToBuffer Re-exports [hexToBuffer](address.md#hextobuffer) @@ -477,12 +412,6 @@ Re-exports [intersection](collections.md#intersection) ___ -### isContact - -Re-exports [isContact](contacts.md#iscontact) - -___ - ### isE164Number Re-exports [isE164Number](phoneNumbers.md#ise164number) @@ -615,12 +544,6 @@ Re-exports [repeatTask](task.md#repeattask) ___ -### resolveCurrency - -Re-exports [resolveCurrency](currencies.md#resolvecurrency) - -___ - ### retryAsync Re-exports [retryAsync](async.md#retryasync) diff --git a/docs/sdk/base/modules/phoneNumbers.md b/docs/sdk/base/modules/phoneNumbers.md index 8e5432b9f..7688bf560 100644 --- a/docs/sdk/base/modules/phoneNumbers.md +++ b/docs/sdk/base/modules/phoneNumbers.md @@ -14,7 +14,6 @@ ### Functions -- [anonymizedPhone](phoneNumbers.md#anonymizedphone) - [isE164Number](phoneNumbers.md#ise164number) ## Variables @@ -31,29 +30,9 @@ #### Defined in -[packages/sdk/base/src/phoneNumbers.ts:19](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/phoneNumbers.ts#L19) - -## Functions - -### anonymizedPhone - -▸ **anonymizedPhone**(`phoneNumber`): `string` - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `phoneNumber` | `string` | - -#### Returns - -`string` - -#### Defined in - [packages/sdk/base/src/phoneNumbers.ts:15](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/base/src/phoneNumbers.ts#L15) -___ +## Functions ### isE164Number diff --git a/docs/sdk/contractkit/enums/celo_tokens.StableToken.md b/docs/sdk/contractkit/enums/celo_tokens.StableToken.md index bc8cd96f3..ad248682f 100644 --- a/docs/sdk/contractkit/enums/celo_tokens.StableToken.md +++ b/docs/sdk/contractkit/enums/celo_tokens.StableToken.md @@ -20,7 +20,7 @@ #### Defined in -packages/sdk/base/lib/currencies.d.ts:9 +packages/sdk/base/lib/currencies.d.ts:3 ___ @@ -30,7 +30,7 @@ ___ #### Defined in -packages/sdk/base/lib/currencies.d.ts:10 +packages/sdk/base/lib/currencies.d.ts:4 ___ @@ -40,4 +40,4 @@ ___ #### Defined in -packages/sdk/base/lib/currencies.d.ts:8 +packages/sdk/base/lib/currencies.d.ts:2 diff --git a/docs/sdk/contractkit/enums/celo_tokens.Token.md b/docs/sdk/contractkit/enums/celo_tokens.Token.md index e9825dd94..642c9fc20 100644 --- a/docs/sdk/contractkit/enums/celo_tokens.Token.md +++ b/docs/sdk/contractkit/enums/celo_tokens.Token.md @@ -18,4 +18,4 @@ #### Defined in -packages/sdk/base/lib/currencies.d.ts:13 +packages/sdk/base/lib/currencies.d.ts:7 diff --git a/docs/sdk/contractkit/modules/celo_tokens.md b/docs/sdk/contractkit/modules/celo_tokens.md index 6b03a3f07..ccaa169fa 100644 --- a/docs/sdk/contractkit/modules/celo_tokens.md +++ b/docs/sdk/contractkit/modules/celo_tokens.md @@ -41,7 +41,7 @@ #### Defined in -packages/sdk/base/lib/currencies.d.ts:15 +packages/sdk/base/lib/currencies.d.ts:9 ___ diff --git a/docs/sdk/utils/README.md b/docs/sdk/utils/README.md index 3d32832e2..e4981eec4 100644 --- a/docs/sdk/utils/README.md +++ b/docs/sdk/utils/README.md @@ -10,9 +10,6 @@ - [async](modules/async.md) - [celoHistory](modules/celoHistory.md) - [collections](modules/collections.md) -- [contacts](modules/contacts.md) -- [currencies](modules/currencies.md) -- [displayFormatting](modules/displayFormatting.md) - [ecdh](modules/ecdh.md) - [ecies](modules/ecies.md) - [fixidity](modules/fixidity.md) diff --git a/docs/sdk/utils/enums/currencies.CURRENCY_ENUM.md b/docs/sdk/utils/enums/currencies.CURRENCY_ENUM.md deleted file mode 100644 index 274225def..000000000 --- a/docs/sdk/utils/enums/currencies.CURRENCY_ENUM.md +++ /dev/null @@ -1,47 +0,0 @@ -[@celo/utils](../README.md) / [currencies](../modules/currencies.md) / CURRENCY\_ENUM - -# Enumeration: CURRENCY\_ENUM - -[currencies](../modules/currencies.md).CURRENCY_ENUM - -**`Deprecated`** - -use StableToken and Token - -## Table of contents - -### Enumeration Members - -- [DOLLAR](currencies.CURRENCY_ENUM.md#dollar) -- [EURO](currencies.CURRENCY_ENUM.md#euro) -- [GOLD](currencies.CURRENCY_ENUM.md#gold) - -## Enumeration Members - -### DOLLAR - -• **DOLLAR** = ``"Celo Dollar"`` - -#### Defined in - -packages/sdk/base/lib/currencies.d.ts:4 - -___ - -### EURO - -• **EURO** = ``"Celo Euro"`` - -#### Defined in - -packages/sdk/base/lib/currencies.d.ts:5 - -___ - -### GOLD - -• **GOLD** = ``"Celo Gold"`` - -#### Defined in - -packages/sdk/base/lib/currencies.d.ts:3 diff --git a/docs/sdk/utils/enums/currencies.SHORT_CURRENCIES.md b/docs/sdk/utils/enums/currencies.SHORT_CURRENCIES.md deleted file mode 100644 index 3e850e517..000000000 --- a/docs/sdk/utils/enums/currencies.SHORT_CURRENCIES.md +++ /dev/null @@ -1,47 +0,0 @@ -[@celo/utils](../README.md) / [currencies](../modules/currencies.md) / SHORT\_CURRENCIES - -# Enumeration: SHORT\_CURRENCIES - -[currencies](../modules/currencies.md).SHORT_CURRENCIES - -**`Deprecated`** - -use StableToken and Token - -## Table of contents - -### Enumeration Members - -- [DOLLAR](currencies.SHORT_CURRENCIES.md#dollar) -- [EURO](currencies.SHORT_CURRENCIES.md#euro) -- [GOLD](currencies.SHORT_CURRENCIES.md#gold) - -## Enumeration Members - -### DOLLAR - -• **DOLLAR** = ``"dollar"`` - -#### Defined in - -packages/sdk/base/lib/currencies.d.ts:29 - -___ - -### EURO - -• **EURO** = ``"euro"`` - -#### Defined in - -packages/sdk/base/lib/currencies.d.ts:31 - -___ - -### GOLD - -• **GOLD** = ``"gold"`` - -#### Defined in - -packages/sdk/base/lib/currencies.d.ts:30 diff --git a/docs/sdk/utils/interfaces/contacts.ContactPhoneNumber.md b/docs/sdk/utils/interfaces/contacts.ContactPhoneNumber.md deleted file mode 100644 index c5a4c9a23..000000000 --- a/docs/sdk/utils/interfaces/contacts.ContactPhoneNumber.md +++ /dev/null @@ -1,32 +0,0 @@ -[@celo/utils](../README.md) / [contacts](../modules/contacts.md) / ContactPhoneNumber - -# Interface: ContactPhoneNumber - -[contacts](../modules/contacts.md).ContactPhoneNumber - -## Table of contents - -### Properties - -- [label](contacts.ContactPhoneNumber.md#label) -- [number](contacts.ContactPhoneNumber.md#number) - -## Properties - -### label - -• `Optional` **label**: `string` - -#### Defined in - -packages/sdk/base/lib/contacts.d.ts:2 - -___ - -### number - -• `Optional` **number**: `string` - -#### Defined in - -packages/sdk/base/lib/contacts.d.ts:3 diff --git a/docs/sdk/utils/interfaces/contacts.MinimalContact.md b/docs/sdk/utils/interfaces/contacts.MinimalContact.md deleted file mode 100644 index 489b88532..000000000 --- a/docs/sdk/utils/interfaces/contacts.MinimalContact.md +++ /dev/null @@ -1,54 +0,0 @@ -[@celo/utils](../README.md) / [contacts](../modules/contacts.md) / MinimalContact - -# Interface: MinimalContact - -[contacts](../modules/contacts.md).MinimalContact - -## Table of contents - -### Properties - -- [displayName](contacts.MinimalContact.md#displayname) -- [phoneNumbers](contacts.MinimalContact.md#phonenumbers) -- [recordID](contacts.MinimalContact.md#recordid) -- [thumbnailPath](contacts.MinimalContact.md#thumbnailpath) - -## Properties - -### displayName - -• `Optional` **displayName**: `string` - -#### Defined in - -packages/sdk/base/lib/contacts.d.ts:7 - -___ - -### phoneNumbers - -• `Optional` **phoneNumbers**: [`ContactPhoneNumber`](contacts.ContactPhoneNumber.md)[] - -#### Defined in - -packages/sdk/base/lib/contacts.d.ts:8 - -___ - -### recordID - -• **recordID**: `string` - -#### Defined in - -packages/sdk/base/lib/contacts.d.ts:6 - -___ - -### thumbnailPath - -• `Optional` **thumbnailPath**: `string` - -#### Defined in - -packages/sdk/base/lib/contacts.d.ts:9 diff --git a/docs/sdk/utils/modules/contacts.md b/docs/sdk/utils/modules/contacts.md deleted file mode 100644 index 0bd226a1e..000000000 --- a/docs/sdk/utils/modules/contacts.md +++ /dev/null @@ -1,80 +0,0 @@ -[@celo/utils](../README.md) / contacts - -# Module: contacts - -## Table of contents - -### Interfaces - -- [ContactPhoneNumber](../interfaces/contacts.ContactPhoneNumber.md) -- [MinimalContact](../interfaces/contacts.MinimalContact.md) - -### Functions - -- [getContactNameHash](contacts.md#getcontactnamehash) -- [getContactPhoneNumber](contacts.md#getcontactphonenumber) -- [isContact](contacts.md#iscontact) - -## Functions - -### getContactNameHash - -▸ **getContactNameHash**(`contact`): `string` - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `contact` | [`MinimalContact`](../interfaces/contacts.MinimalContact.md) | - -#### Returns - -`string` - -**`Deprecated`** - -May be removed in future - -#### Defined in - -[packages/sdk/utils/src/contacts.ts:16](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/utils/src/contacts.ts#L16) - -___ - -### getContactPhoneNumber - -▸ **getContactPhoneNumber**(`contact`): `undefined` \| ``null`` \| `string` - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `contact` | [`MinimalContact`](../interfaces/contacts.MinimalContact.md) | - -#### Returns - -`undefined` \| ``null`` \| `string` - -#### Defined in - -packages/sdk/base/lib/contacts.d.ts:11 - -___ - -### isContact - -▸ **isContact**(`contactOrNumber`): contactOrNumber is MinimalContact - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `contactOrNumber` | `any` | - -#### Returns - -contactOrNumber is MinimalContact - -#### Defined in - -packages/sdk/base/lib/contacts.d.ts:12 diff --git a/docs/sdk/utils/modules/currencies.md b/docs/sdk/utils/modules/currencies.md deleted file mode 100644 index 630430779..000000000 --- a/docs/sdk/utils/modules/currencies.md +++ /dev/null @@ -1,73 +0,0 @@ -[@celo/utils](../README.md) / currencies - -# Module: currencies - -## Table of contents - -### Enumerations - -- [CURRENCY\_ENUM](../enums/currencies.CURRENCY_ENUM.md) -- [SHORT\_CURRENCIES](../enums/currencies.SHORT_CURRENCIES.md) - -### Variables - -- [CURRENCIES](currencies.md#currencies) -- [currencyToShortMap](currencies.md#currencytoshortmap) - -### Functions - -- [resolveCurrency](currencies.md#resolvecurrency) - -## Variables - -### CURRENCIES - -• `Const` **CURRENCIES**: `CurrencyObject` - -**`Deprecated`** - -#### Defined in - -packages/sdk/base/lib/currencies.d.ts:25 - -___ - -### currencyToShortMap - -• `Const` **currencyToShortMap**: `Object` - -**`Deprecated`** - -use StableToken and Token - -#### Type declaration - -| Name | Type | -| :------ | :------ | -| `Celo Dollar` | [`SHORT_CURRENCIES`](../enums/currencies.SHORT_CURRENCIES.md) | -| `Celo Euro` | [`SHORT_CURRENCIES`](../enums/currencies.SHORT_CURRENCIES.md) | -| `Celo Gold` | [`SHORT_CURRENCIES`](../enums/currencies.SHORT_CURRENCIES.md) | - -#### Defined in - -packages/sdk/base/lib/currencies.d.ts:34 - -## Functions - -### resolveCurrency - -▸ **resolveCurrency**(`label`): [`CURRENCY_ENUM`](../enums/currencies.CURRENCY_ENUM.md) - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `label` | `string` | - -#### Returns - -[`CURRENCY_ENUM`](../enums/currencies.CURRENCY_ENUM.md) - -#### Defined in - -packages/sdk/base/lib/currencies.d.ts:26 diff --git a/docs/sdk/utils/modules/displayFormatting.md b/docs/sdk/utils/modules/displayFormatting.md deleted file mode 100644 index e63213b69..000000000 --- a/docs/sdk/utils/modules/displayFormatting.md +++ /dev/null @@ -1,29 +0,0 @@ -[@celo/utils](../README.md) / displayFormatting - -# Module: displayFormatting - -## Table of contents - -### Functions - -- [getErrorMessage](displayFormatting.md#geterrormessage) - -## Functions - -### getErrorMessage - -▸ **getErrorMessage**(`error`): `string` - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `error` | `Error` | - -#### Returns - -`string` - -#### Defined in - -packages/sdk/base/lib/displayFormatting.d.ts:2 diff --git a/docs/sdk/utils/modules/index.md b/docs/sdk/utils/modules/index.md index 2d644b7ec..70101e96f 100644 --- a/docs/sdk/utils/modules/index.md +++ b/docs/sdk/utils/modules/index.md @@ -7,20 +7,10 @@ ### References - [AddressUtils](index.md#addressutils) -- [CURRENCIES](index.md#currencies) -- [CURRENCY\_ENUM](index.md#currency_enum) -- [ContactPhoneNumber](index.md#contactphonenumber) - [ECIES](index.md#ecies) - [IstanbulUtils](index.md#istanbulutils) -- [MinimalContact](index.md#minimalcontact) -- [SHORT\_CURRENCIES](index.md#short_currencies) - [SignatureUtils](index.md#signatureutils) - [StringUtils](index.md#stringutils) -- [currencyToShortMap](index.md#currencytoshortmap) -- [getContactNameHash](index.md#getcontactnamehash) -- [getContactPhoneNumber](index.md#getcontactphonenumber) -- [isContact](index.md#iscontact) -- [resolveCurrency](index.md#resolvecurrency) ## References @@ -30,24 +20,6 @@ Renames and re-exports [address](address.md) ___ -### CURRENCIES - -Re-exports [CURRENCIES](currencies.md#currencies) - -___ - -### CURRENCY\_ENUM - -Re-exports [CURRENCY_ENUM](../enums/currencies.CURRENCY_ENUM.md) - -___ - -### ContactPhoneNumber - -Re-exports [ContactPhoneNumber](../interfaces/contacts.ContactPhoneNumber.md) - -___ - ### ECIES Re-exports [ECIES](ecies.md#ecies) @@ -60,18 +32,6 @@ Re-exports [IstanbulUtils](istanbul.md#istanbulutils) ___ -### MinimalContact - -Re-exports [MinimalContact](../interfaces/contacts.MinimalContact.md) - -___ - -### SHORT\_CURRENCIES - -Re-exports [SHORT_CURRENCIES](../enums/currencies.SHORT_CURRENCIES.md) - -___ - ### SignatureUtils Re-exports [SignatureUtils](signatureUtils.md#signatureutils) @@ -81,33 +41,3 @@ ___ ### StringUtils Re-exports [StringUtils](string.md#stringutils) - -___ - -### currencyToShortMap - -Re-exports [currencyToShortMap](currencies.md#currencytoshortmap) - -___ - -### getContactNameHash - -Re-exports [getContactNameHash](contacts.md#getcontactnamehash) - -___ - -### getContactPhoneNumber - -Re-exports [getContactPhoneNumber](contacts.md#getcontactphonenumber) - -___ - -### isContact - -Re-exports [isContact](contacts.md#iscontact) - -___ - -### resolveCurrency - -Re-exports [resolveCurrency](currencies.md#resolvecurrency) diff --git a/packages/sdk/base/src/contacts.ts b/packages/sdk/base/src/contacts.ts deleted file mode 100644 index f65572021..000000000 --- a/packages/sdk/base/src/contacts.ts +++ /dev/null @@ -1,31 +0,0 @@ -export interface ContactPhoneNumber { - label?: string - number?: string -} - -export interface MinimalContact { - recordID: string - displayName?: string - phoneNumbers?: ContactPhoneNumber[] - thumbnailPath?: string -} - -export const getContactPhoneNumber = (contact: MinimalContact) => { - if (!contact) { - throw new Error('Invalid contact') - } - - if (!contact.phoneNumbers || !contact.phoneNumbers.length) { - return null - } - - // TODO(Rossy) find the right phone number based on the address - return contact.phoneNumbers[0].number -} - -export function isContact(contactOrNumber: any): contactOrNumber is MinimalContact { - if (typeof contactOrNumber === 'object') { - return 'recordID' in contactOrNumber - } - return false -} diff --git a/packages/sdk/base/src/currencies.ts b/packages/sdk/base/src/currencies.ts index 2bfbd8788..19105b835 100644 --- a/packages/sdk/base/src/currencies.ts +++ b/packages/sdk/base/src/currencies.ts @@ -1,10 +1,3 @@ -/** @deprecated use StableToken and Token */ -export enum CURRENCY_ENUM { - GOLD = 'Celo Gold', - DOLLAR = 'Celo Dollar', - EURO = 'Celo Euro', -} - export enum StableToken { cUSD = 'cUSD', cEUR = 'cEUR', @@ -16,57 +9,3 @@ export enum Token { } export type CeloTokenType = StableToken | Token - -interface Currency { - symbol: string - code: string - displayDecimals: number -} - -type CurrencyObject = { [key in CURRENCY_ENUM]: Currency } - -/** @deprecated */ -export const CURRENCIES: CurrencyObject = { - [CURRENCY_ENUM.GOLD]: { - symbol: '', - code: 'cGLD', - displayDecimals: 3, - }, - [CURRENCY_ENUM.DOLLAR]: { - symbol: '$', - code: 'cUSD', - displayDecimals: 2, - }, - [CURRENCY_ENUM.EURO]: { - symbol: '€', - code: 'cEUR', - displayDecimals: 2, - }, -} - -export const resolveCurrency = (label: string): CURRENCY_ENUM => { - if (label && label.toLowerCase().includes('dollar')) { - return CURRENCY_ENUM.DOLLAR - } else if (label && label.toLowerCase().includes('euro')) { - return CURRENCY_ENUM.EURO - } else if (label && label.toLowerCase().includes('gold')) { - return CURRENCY_ENUM.GOLD - } else { - console.info('Unable to resolve currency from label: ' + label) - return CURRENCY_ENUM.DOLLAR - } -} - -/** @deprecated use StableToken and Token */ -export enum SHORT_CURRENCIES { - DOLLAR = 'dollar', - GOLD = 'gold', - EURO = 'euro', -} - -/** @deprecated use StableToken and Token */ -export const currencyToShortMap = { - [CURRENCY_ENUM.DOLLAR]: SHORT_CURRENCIES.DOLLAR, - [CURRENCY_ENUM.GOLD]: SHORT_CURRENCIES.GOLD, - [CURRENCY_ENUM.EURO]: SHORT_CURRENCIES.EURO, -} diff --git a/packages/sdk/base/src/displayFormatting.ts b/packages/sdk/base/src/displayFormatting.ts deleted file mode 100644 index 6d9a85662..000000000 --- a/packages/sdk/base/src/displayFormatting.ts +++ /dev/null @@ -1,11 +0,0 @@ -/** @internal */ -export function getErrorMessage(error: Error) { - // This replacement is because when the error reaches here, it's been wrapped - // by Error: multiple times - let errorMsg = error.message || error.name || 'unknown' - errorMsg = errorMsg.replace(/Error:/g, '') - if (error.stack) { - errorMsg += ' in ' + error.stack.substring(0, 100) - } - return errorMsg -} diff --git a/packages/sdk/base/src/index.ts b/packages/sdk/base/src/index.ts index 716c6645e..084f00fdf 100644 --- a/packages/sdk/base/src/index.ts +++ b/packages/sdk/base/src/index.ts @@ -2,9 +2,7 @@ export * from './account' export * from './address' export * from './async' export * from './collections' -export * from './contacts' export * from './currencies' -export * from './displayFormatting' export * from './future' export * from './inputValidation' export * from './io' diff --git a/packages/sdk/base/src/phoneNumbers.ts b/packages/sdk/base/src/phoneNumbers.ts index 1334c0f9e..84bc29f4f 100644 --- a/packages/sdk/base/src/phoneNumbers.ts +++ b/packages/sdk/base/src/phoneNumbers.ts @@ -12,10 +12,6 @@ export function isE164Number(phoneNumber: string) { return E164_REGEX.test(phoneNumber) } -export function anonymizedPhone(phoneNumber: string) { - return phoneNumber.slice(0, -4) + 'XXXX' -} - export const PhoneNumberBase = { isE164Number, } diff --git a/packages/sdk/metadata-claims/lib/account.d.ts b/packages/sdk/metadata-claims/lib/account.d.ts new file mode 100644 index 000000000..e12432041 --- /dev/null +++ b/packages/sdk/metadata-claims/lib/account.d.ts @@ -0,0 +1,20 @@ +import * as t from 'io-ts'; +import { ClaimTypes } from './types'; +/** + * + * Provide the type minus the validation that the public key and address are derived from the same private key + */ +export declare const AccountClaimTypeH: t.TypeC<{ + type: t.LiteralC; + timestamp: t.NumberC; + address: t.Type; + publicKey: t.UnionC<[t.UndefinedC, t.Type]>; +}>; +export declare const AccountClaimType: t.Type<{ + type: ClaimTypes.ACCOUNT; + timestamp: number; + address: string; + publicKey: string | undefined; +}, any, unknown>; +export type AccountClaim = t.TypeOf; +export declare const createAccountClaim: (address: string, publicKey?: string) => AccountClaim; diff --git a/packages/sdk/metadata-claims/lib/account.js b/packages/sdk/metadata-claims/lib/account.js new file mode 100644 index 000000000..5363a4440 --- /dev/null +++ b/packages/sdk/metadata-claims/lib/account.js @@ -0,0 +1,66 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createAccountClaim = exports.AccountClaimType = exports.AccountClaimTypeH = void 0; +const address_1 = require("@celo/utils/lib/address"); +const io_1 = require("@celo/utils/lib/io"); +const Either_1 = require("fp-ts/lib/Either"); +const t = __importStar(require("io-ts")); +const types_1 = require("./types"); +/** + * + * Provide the type minus the validation that the public key and address are derived from the same private key + */ +exports.AccountClaimTypeH = t.type({ + type: t.literal(types_1.ClaimTypes.ACCOUNT), + timestamp: types_1.TimestampType, + address: io_1.AddressType, + // io-ts way of defining optional key-value pair + publicKey: t.union([t.undefined, io_1.PublicKeyType]), +}); +exports.AccountClaimType = new t.Type('AccountClaimType', exports.AccountClaimTypeH.is, (unknownValue, context) => Either_1.either.chain(exports.AccountClaimTypeH.validate(unknownValue, context), (claim) => { + if (claim.publicKey === undefined) { + return t.success(claim); + } + const derivedAddress = (0, address_1.publicKeyToAddress)(claim.publicKey); + return derivedAddress === claim.address + ? t.success(claim) + : t.failure(claim, context, 'public key did not match the address in the claim'); +}), (x) => x); +const createAccountClaim = (address, publicKey) => { + const claim = { + timestamp: (0, types_1.now)(), + type: types_1.ClaimTypes.ACCOUNT, + address, + publicKey, + }; + const parsedClaim = exports.AccountClaimType.decode(claim); + if ((0, Either_1.isLeft)(parsedClaim)) { + throw new Error(`A valid claim could not be created`); + } + return parsedClaim.right; +}; +exports.createAccountClaim = createAccountClaim; +//# sourceMappingURL=account.js.map \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/account.js.map b/packages/sdk/metadata-claims/lib/account.js.map new file mode 100644 index 000000000..a132a0119 --- /dev/null +++ b/packages/sdk/metadata-claims/lib/account.js.map @@ -0,0 +1 @@ +{"version":3,"file":"account.js","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAA4D;AAC5D,2CAA+D;AAC/D,6CAAiD;AACjD,yCAA0B;AAC1B,mCAAwD;AAExD;;;GAGG;AACU,QAAA,iBAAiB,GAAG,CAAC,CAAC,IAAI,CAAC;IACtC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,kBAAU,CAAC,OAAO,CAAC;IACnC,SAAS,EAAE,qBAAa;IACxB,OAAO,EAAE,gBAAW;IACpB,gDAAgD;IAChD,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,kBAAa,CAAC,CAAC;CACjD,CAAC,CAAA;AAEW,QAAA,gBAAgB,GAAG,IAAI,CAAC,CAAC,IAAI,CACxC,kBAAkB,EAClB,yBAAiB,CAAC,EAAE,EACpB,CAAC,YAAY,EAAE,OAAO,EAAE,EAAE,CACxB,eAAM,CAAC,KAAK,CAAC,yBAAiB,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE;IACxE,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QAClC,OAAO,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACzB,CAAC;IACD,MAAM,cAAc,GAAG,IAAA,4BAAkB,EAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IAC1D,OAAO,cAAc,KAAK,KAAK,CAAC,OAAO;QACrC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;QAClB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,mDAAmD,CAAC,CAAA;AACpF,CAAC,CAAC,EACJ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CACT,CAAA;AAIM,MAAM,kBAAkB,GAAG,CAAC,OAAe,EAAE,SAAkB,EAAgB,EAAE;IACtF,MAAM,KAAK,GAAG;QACZ,SAAS,EAAE,IAAA,WAAG,GAAE;QAChB,IAAI,EAAE,kBAAU,CAAC,OAAO;QACxB,OAAO;QACP,SAAS;KACV,CAAA;IAED,MAAM,WAAW,GAAG,wBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAElD,IAAI,IAAA,eAAM,EAAC,WAAW,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAA;IACvD,CAAC;IAED,OAAO,WAAW,CAAC,KAAK,CAAA;AAC1B,CAAC,CAAA;AAfY,QAAA,kBAAkB,sBAe9B"} \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/claim.d.ts b/packages/sdk/metadata-claims/lib/claim.d.ts new file mode 100644 index 000000000..2f53fd188 --- /dev/null +++ b/packages/sdk/metadata-claims/lib/claim.d.ts @@ -0,0 +1,89 @@ +import * as t from 'io-ts'; +import { AccountClaim } from './account'; +import { ClaimTypes } from './types'; +export declare const KeybaseClaimType: t.TypeC<{ + type: t.LiteralC; + timestamp: t.NumberC; + username: t.StringC; +}>; +export type KeybaseClaim = t.TypeOf; +declare const DomainClaimType: t.TypeC<{ + type: t.LiteralC; + timestamp: t.NumberC; + domain: t.StringC; +}>; +declare const NameClaimType: t.TypeC<{ + type: t.LiteralC; + timestamp: t.NumberC; + name: t.StringC; +}>; +declare const StorageClaimType: t.TypeC<{ + type: t.LiteralC; + timestamp: t.NumberC; + address: t.StringC; + filteredDataPaths: t.StringC; +}>; +export declare const ClaimType: t.UnionC<[t.Type<{ + type: ClaimTypes.ACCOUNT; + timestamp: number; + address: string; + publicKey: string | undefined; +}, any, unknown>, t.TypeC<{ + type: t.LiteralC; + timestamp: t.NumberC; + domain: t.StringC; +}>, t.TypeC<{ + type: t.LiteralC; + timestamp: t.NumberC; + username: t.StringC; +}>, t.TypeC<{ + type: t.LiteralC; + timestamp: t.NumberC; + name: t.StringC; +}>, t.TypeC<{ + type: t.LiteralC; + timestamp: t.NumberC; + address: t.StringC; + filteredDataPaths: t.StringC; +}>]>; +export declare const SignedClaimType: t.TypeC<{ + claim: t.UnionC<[t.Type<{ + type: ClaimTypes.ACCOUNT; + timestamp: number; + address: string; + publicKey: string | undefined; + }, any, unknown>, t.TypeC<{ + type: t.LiteralC; + timestamp: t.NumberC; + domain: t.StringC; + }>, t.TypeC<{ + type: t.LiteralC; + timestamp: t.NumberC; + username: t.StringC; + }>, t.TypeC<{ + type: t.LiteralC; + timestamp: t.NumberC; + name: t.StringC; + }>, t.TypeC<{ + type: t.LiteralC; + timestamp: t.NumberC; + address: t.StringC; + filteredDataPaths: t.StringC; + }>]>; + signature: t.StringC; +}>; +export declare const DOMAIN_TXT_HEADER = "celo-site-verification"; +export type DomainClaim = t.TypeOf; +export type NameClaim = t.TypeOf; +export type StorageClaim = t.TypeOf; +export type Claim = DomainClaim | KeybaseClaim | NameClaim | AccountClaim | StorageClaim; +export type ClaimPayload = K extends typeof ClaimTypes.DOMAIN ? DomainClaim : K extends typeof ClaimTypes.NAME ? NameClaim : K extends typeof ClaimTypes.KEYBASE ? KeybaseClaim : K extends typeof ClaimTypes.ACCOUNT ? AccountClaim : StorageClaim; +/** @internal */ +export declare const isOfType: (type: K) => (data: Claim) => data is ClaimPayload; +export declare function hashOfClaim(claim: Claim): string; +export declare function hashOfClaims(claims: Claim[]): string; +export declare function serializeClaim(claim: Claim): string; +export declare const createNameClaim: (name: string) => NameClaim; +export declare const createDomainClaim: (domain: string) => DomainClaim; +export declare const createStorageClaim: (storageURL: string) => StorageClaim; +export {}; diff --git a/packages/sdk/metadata-claims/lib/claim.js b/packages/sdk/metadata-claims/lib/claim.js new file mode 100644 index 000000000..09e271edd --- /dev/null +++ b/packages/sdk/metadata-claims/lib/claim.js @@ -0,0 +1,100 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createStorageClaim = exports.createDomainClaim = exports.createNameClaim = exports.serializeClaim = exports.hashOfClaims = exports.hashOfClaim = exports.isOfType = exports.DOMAIN_TXT_HEADER = exports.SignedClaimType = exports.ClaimType = exports.KeybaseClaimType = void 0; +const signatureUtils_1 = require("@celo/utils/lib/signatureUtils"); +const t = __importStar(require("io-ts")); +const account_1 = require("./account"); +const types_1 = require("./types"); +exports.KeybaseClaimType = t.type({ + type: t.literal(types_1.ClaimTypes.KEYBASE), + timestamp: types_1.TimestampType, + // TODO: Validate compliant username before just interpolating + username: t.string, +}); +const DomainClaimType = t.type({ + type: t.literal(types_1.ClaimTypes.DOMAIN), + timestamp: types_1.TimestampType, + domain: t.string, +}); +const NameClaimType = t.type({ + type: t.literal(types_1.ClaimTypes.NAME), + timestamp: types_1.TimestampType, + name: t.string, +}); +const StorageClaimType = t.type({ + type: t.literal(types_1.ClaimTypes.STORAGE), + timestamp: types_1.TimestampType, + address: t.string, + filteredDataPaths: t.string, +}); +exports.ClaimType = t.union([ + account_1.AccountClaimType, + DomainClaimType, + exports.KeybaseClaimType, + NameClaimType, + StorageClaimType, +]); +exports.SignedClaimType = t.type({ + claim: exports.ClaimType, + signature: types_1.SignatureType, +}); +exports.DOMAIN_TXT_HEADER = 'celo-site-verification'; +/** @internal */ +const isOfType = (type) => (data) => data.type === type; +exports.isOfType = isOfType; +function hashOfClaim(claim) { + return (0, signatureUtils_1.hashMessage)(serializeClaim(claim)); +} +exports.hashOfClaim = hashOfClaim; +function hashOfClaims(claims) { + const hashes = claims.map(hashOfClaim); + return (0, signatureUtils_1.hashMessage)(hashes.join('')); +} +exports.hashOfClaims = hashOfClaims; +function serializeClaim(claim) { + return JSON.stringify(claim); +} +exports.serializeClaim = serializeClaim; +const createNameClaim = (name) => ({ + name, + timestamp: (0, types_1.now)(), + type: types_1.ClaimTypes.NAME, +}); +exports.createNameClaim = createNameClaim; +const createDomainClaim = (domain) => ({ + domain, + timestamp: (0, types_1.now)(), + type: types_1.ClaimTypes.DOMAIN, +}); +exports.createDomainClaim = createDomainClaim; +const createStorageClaim = (storageURL) => ({ + address: storageURL, + timestamp: (0, types_1.now)(), + type: types_1.ClaimTypes.STORAGE, + filteredDataPaths: '.*', +}); +exports.createStorageClaim = createStorageClaim; +//# sourceMappingURL=claim.js.map \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/claim.js.map b/packages/sdk/metadata-claims/lib/claim.js.map new file mode 100644 index 000000000..22f700491 --- /dev/null +++ b/packages/sdk/metadata-claims/lib/claim.js.map @@ -0,0 +1 @@ +{"version":3,"file":"claim.js","sourceRoot":"","sources":["../src/claim.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mEAA4D;AAC5D,yCAA0B;AAC1B,uCAA0D;AAC1D,mCAAuE;AAE1D,QAAA,gBAAgB,GAAG,CAAC,CAAC,IAAI,CAAC;IACrC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,kBAAU,CAAC,OAAO,CAAC;IACnC,SAAS,EAAE,qBAAa;IACxB,8DAA8D;IAC9D,QAAQ,EAAE,CAAC,CAAC,MAAM;CACnB,CAAC,CAAA;AAGF,MAAM,eAAe,GAAG,CAAC,CAAC,IAAI,CAAC;IAC7B,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,kBAAU,CAAC,MAAM,CAAC;IAClC,SAAS,EAAE,qBAAa;IACxB,MAAM,EAAE,CAAC,CAAC,MAAM;CACjB,CAAC,CAAA;AAEF,MAAM,aAAa,GAAG,CAAC,CAAC,IAAI,CAAC;IAC3B,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,kBAAU,CAAC,IAAI,CAAC;IAChC,SAAS,EAAE,qBAAa;IACxB,IAAI,EAAE,CAAC,CAAC,MAAM;CACf,CAAC,CAAA;AAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,IAAI,CAAC;IAC9B,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,kBAAU,CAAC,OAAO,CAAC;IACnC,SAAS,EAAE,qBAAa;IACxB,OAAO,EAAE,CAAC,CAAC,MAAM;IACjB,iBAAiB,EAAE,CAAC,CAAC,MAAM;CAC5B,CAAC,CAAA;AAEW,QAAA,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC;IAC/B,0BAAgB;IAChB,eAAe;IACf,wBAAgB;IAChB,aAAa;IACb,gBAAgB;CACjB,CAAC,CAAA;AAEW,QAAA,eAAe,GAAG,CAAC,CAAC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AAE;IAChB,IAAI,EAAE,kBAAU,CAAC,OAAO;IACxB,iBAAiB,EAAE,IAAI;CACxB,CAAC,CAAA;AALW,QAAA,kBAAkB,sBAK7B"} \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/index.d.ts b/packages/sdk/metadata-claims/lib/index.d.ts new file mode 100644 index 000000000..31b421c8b --- /dev/null +++ b/packages/sdk/metadata-claims/lib/index.d.ts @@ -0,0 +1,2 @@ +export { Claim, createNameClaim } from './claim'; +export * from './metadata'; diff --git a/packages/sdk/metadata-claims/lib/index.js b/packages/sdk/metadata-claims/lib/index.js new file mode 100644 index 000000000..3075c7632 --- /dev/null +++ b/packages/sdk/metadata-claims/lib/index.js @@ -0,0 +1,21 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createNameClaim = void 0; +var claim_1 = require("./claim"); +Object.defineProperty(exports, "createNameClaim", { enumerable: true, get: function () { return claim_1.createNameClaim; } }); +__exportStar(require("./metadata"), exports); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/index.js.map b/packages/sdk/metadata-claims/lib/index.js.map new file mode 100644 index 000000000..b795a3c59 --- /dev/null +++ b/packages/sdk/metadata-claims/lib/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,iCAAgD;AAAhC,wGAAA,eAAe,OAAA;AAC/B,6CAA0B"} \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/keybase.d.ts b/packages/sdk/metadata-claims/lib/keybase.d.ts new file mode 100644 index 000000000..5ecb73a92 --- /dev/null +++ b/packages/sdk/metadata-claims/lib/keybase.d.ts @@ -0,0 +1,19 @@ +import { Address } from '@celo/base/lib/address'; +import { KeybaseClaim } from './claim'; +import { AccountMetadataSignerGetters } from './types'; +export declare const keybaseFilePathToProof = ".well-known/celo/"; +export declare const proofFileName: (address: Address) => string; +export declare const targetURL: (username: string, address: Address) => string; +/** + * + * @remarks + * If verification encounters an error, returns the error message as a string + * otherwise returns undefined when successful + * + * @param accountsInfoGetters + * @param claim + * @param signer + * @returns a human readable string with claims (non)verifiability or undefined + */ +export declare function verifyKeybaseClaim(accountsInfoGetters: AccountMetadataSignerGetters, claim: KeybaseClaim, signer: Address): Promise; +export declare const createKeybaseClaim: (username: string) => KeybaseClaim; diff --git a/packages/sdk/metadata-claims/lib/keybase.js b/packages/sdk/metadata-claims/lib/keybase.js new file mode 100644 index 000000000..b327ca9c8 --- /dev/null +++ b/packages/sdk/metadata-claims/lib/keybase.js @@ -0,0 +1,74 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createKeybaseClaim = exports.verifyKeybaseClaim = exports.targetURL = exports.proofFileName = exports.keybaseFilePathToProof = void 0; +const cross_fetch_1 = __importDefault(require("cross-fetch")); +const Either_1 = require("fp-ts/lib/Either"); +const claim_1 = require("./claim"); +const metadata_1 = require("./metadata"); +const types_1 = require("./types"); +exports.keybaseFilePathToProof = `.well-known/celo/`; +const proofFileName = (address) => `verify-${address}.json`; +exports.proofFileName = proofFileName; +const targetURL = (username, address) => `https://${username}.keybase.pub/${exports.keybaseFilePathToProof}${(0, exports.proofFileName)(address)}`; +exports.targetURL = targetURL; +/** + * + * @remarks + * If verification encounters an error, returns the error message as a string + * otherwise returns undefined when successful + * + * @param accountsInfoGetters + * @param claim + * @param signer + * @returns a human readable string with claims (non)verifiability or undefined + */ +function verifyKeybaseClaim(accountsInfoGetters, claim, signer) { + return __awaiter(this, void 0, void 0, function* () { + try { + const resp = yield (0, cross_fetch_1.default)((0, exports.targetURL)(claim.username, signer)); + if (!resp.ok) { + return `Proof of ownership could not be retrieved at ${(0, exports.targetURL)(claim.username, signer)}, request yielded ${resp.status} status code`; + } + const jsonResp = yield resp.json(); + const parsedClaim = claim_1.SignedClaimType.decode(jsonResp); + if ((0, Either_1.isLeft)(parsedClaim)) { + return 'Claim is incorrectly formatted'; + } + const hasValidSignature = yield metadata_1.IdentityMetadataWrapper.verifySignerForAddress(accountsInfoGetters, (0, claim_1.hashOfClaim)(parsedClaim.right.claim), parsedClaim.right.signature, signer); + if (!hasValidSignature) { + return 'Claim does not contain a valid signature'; + } + const parsedKeybaseClaim = claim_1.KeybaseClaimType.decode(parsedClaim.right.claim); + if ((0, Either_1.isLeft)(parsedKeybaseClaim)) { + return 'Hosted claim is not a Keybase claim'; + } + if (parsedKeybaseClaim.right.username !== claim.username) { + return 'Usernames do not match'; + } + return; + } + catch (error) { + return 'Could not verify Keybase claim: ' + error; + } + }); +} +exports.verifyKeybaseClaim = verifyKeybaseClaim; +const createKeybaseClaim = (username) => ({ + username, + timestamp: (0, types_1.now)(), + type: types_1.ClaimTypes.KEYBASE, +}); +exports.createKeybaseClaim = createKeybaseClaim; +//# sourceMappingURL=keybase.js.map \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/keybase.js.map b/packages/sdk/metadata-claims/lib/keybase.js.map new file mode 100644 index 000000000..c916f044f --- /dev/null +++ b/packages/sdk/metadata-claims/lib/keybase.js.map @@ -0,0 +1 @@ +{"version":3,"file":"keybase.js","sourceRoot":"","sources":["../src/keybase.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,8DAA+B;AAC/B,6CAAyC;AACzC,mCAAsF;AACtF,yCAAoD;AACpD,mCAAuE;AAE1D,QAAA,sBAAsB,GAAG,mBAAmB,CAAA;AAClD,MAAM,aAAa,GAAG,CAAC,OAAgB,EAAE,EAAE,CAAC,UAAU,OAAO,OAAO,CAAA;AAA9D,QAAA,aAAa,iBAAiD;AACpE,MAAM,SAAS,GAAG,CAAC,QAAgB,EAAE,OAAgB,EAAE,EAAE,CAC9D,WAAW,QAAQ,gBAAgB,8BAAsB,GAAG,IAAA,qBAAa,EAAC,OAAO,CAAC,EAAE,CAAA;AADzE,QAAA,SAAS,aACgE;AAEtF;;;;;;;;;;GAUG;AAEH,SAAsB,kBAAkB,CACtC,mBAAiD,EACjD,KAAmB,EACnB,MAAe;;QAEf,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAA,qBAAK,EAAC,IAAA,iBAAS,EAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAA;YAC3D,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;gBACb,OAAO,gDAAgD,IAAA,iBAAS,EAC9D,KAAK,CAAC,QAAQ,EACd,MAAM,CACP,qBAAqB,IAAI,CAAC,MAAM,cAAc,CAAA;YACjD,CAAC;YAED,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,CAAA;YAClC,MAAM,WAAW,GAAG,uBAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;YACpD,IAAI,IAAA,eAAM,EAAC,WAAW,CAAC,EAAE,CAAC;gBACxB,OAAO,gCAAgC,CAAA;YACzC,CAAC;YAED,MAAM,iBAAiB,GAAG,MAAM,kCAAuB,CAAC,sBAAsB,CAC5E,mBAAmB,EACnB,IAAA,mBAAW,EAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,EACpC,WAAW,CAAC,KAAK,CAAC,SAAS,EAC3B,MAAM,CACP,CAAA;YAED,IAAI,CAAC,iBAAiB,EAAE,CAAC;gBACvB,OAAO,0CAA0C,CAAA;YACnD,CAAC;YAED,MAAM,kBAAkB,GAAG,wBAAgB,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YAC3E,IAAI,IAAA,eAAM,EAAC,kBAAkB,CAAC,EAAE,CAAC;gBAC/B,OAAO,qCAAqC,CAAA;YAC9C,CAAC;YAED,IAAI,kBAAkB,CAAC,KAAK,CAAC,QAAQ,KAAK,KAAK,CAAC,QAAQ,EAAE,CAAC;gBACzD,OAAO,wBAAwB,CAAA;YACjC,CAAC;YAED,OAAM;QACR,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,kCAAkC,GAAG,KAAK,CAAA;QACnD,CAAC;IACH,CAAC;CAAA;AA5CD,gDA4CC;AAEM,MAAM,kBAAkB,GAAG,CAAC,QAAgB,EAAgB,EAAE,CAAC,CAAC;IACrE,QAAQ;IACR,SAAS,EAAE,IAAA,WAAG,GAAE;IAChB,IAAI,EAAE,kBAAU,CAAC,OAAO;CACzB,CAAC,CAAA;AAJW,QAAA,kBAAkB,sBAI7B"} \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/metadata.d.ts b/packages/sdk/metadata-claims/lib/metadata.d.ts new file mode 100644 index 000000000..ae5bcd7d0 --- /dev/null +++ b/packages/sdk/metadata-claims/lib/metadata.d.ts @@ -0,0 +1,75 @@ +import { Address } from '@celo/base/lib/address'; +import { Signer } from '@celo/base/lib/signatureUtils'; +import * as t from 'io-ts'; +import { Claim, ClaimPayload } from './claim'; +import { AccountMetadataSignerGetters, ClaimTypes } from './types'; +export { ClaimTypes } from './types'; +type KitOrAccountsWrapper = AccountMetadataSignerGetters; +export declare const IdentityMetadataType: t.TypeC<{ + claims: t.ArrayC, t.TypeC<{ + type: t.LiteralC; + timestamp: t.NumberC; + domain: t.StringC; + }>, t.TypeC<{ + type: t.LiteralC; + timestamp: t.NumberC; + username: t.StringC; + }>, t.TypeC<{ + type: t.LiteralC; + timestamp: t.NumberC; + name: t.StringC; + }>, t.TypeC<{ + type: t.LiteralC; + timestamp: t.NumberC; + address: t.StringC; + filteredDataPaths: t.StringC; + }>]>>; + meta: t.TypeC<{ + address: t.Type; + signature: t.StringC; + }>; +}>; +export type IdentityMetadata = t.TypeOf; +export declare class IdentityMetadataWrapper { + data: IdentityMetadata; + static fromEmpty(address: Address): IdentityMetadataWrapper; + static fetchFromURL(contractKitOrAccountsWrapper: KitOrAccountsWrapper, url: string, tries?: number): Promise; + static fromFile(contractKitOrAccountsWrapper: KitOrAccountsWrapper, path: string): Promise; + static verifySigner(contractKitOrAccountsWrapper: KitOrAccountsWrapper, hash: any, signature: any, metadata: any): Promise; + static verifySignerForAddress(contractKitOrAccountsWrapper: KitOrAccountsWrapper, hash: any, signature: any, address: Address): Promise; + static fromRawString(contractKitOrAccountsWrapper: KitOrAccountsWrapper, rawData: string): Promise; + constructor(data: IdentityMetadata); + get claims(): ({ + type: ClaimTypes.ACCOUNT; + timestamp: number; + address: string; + publicKey: string | undefined; + } | { + type: ClaimTypes.KEYBASE; + timestamp: number; + username: string; + } | { + type: ClaimTypes.DOMAIN; + timestamp: number; + domain: string; + } | { + type: ClaimTypes.NAME; + timestamp: number; + name: string; + } | { + type: ClaimTypes.STORAGE; + timestamp: number; + address: string; + filteredDataPaths: string; + })[]; + hashOfClaims(): string; + toString(): string; + addClaim(claim: Claim, signer: Signer): Promise; + findClaim(type: K): ClaimPayload | undefined; + filterClaims(type: K): ClaimPayload[]; +} diff --git a/packages/sdk/metadata-claims/lib/metadata.js b/packages/sdk/metadata-claims/lib/metadata.js new file mode 100644 index 000000000..41bbfe0f5 --- /dev/null +++ b/packages/sdk/metadata-claims/lib/metadata.js @@ -0,0 +1,212 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.IdentityMetadataWrapper = exports.IdentityMetadataType = exports.ClaimTypes = void 0; +const address_1 = require("@celo/base/lib/address"); +const async_1 = require("@celo/base/lib/async"); +const io_1 = require("@celo/utils/lib/io"); +const signatureUtils_1 = require("@celo/utils/lib/signatureUtils"); +const cross_fetch_1 = __importDefault(require("cross-fetch")); +const Either_1 = require("fp-ts/lib/Either"); +const t = __importStar(require("io-ts")); +const PathReporter_1 = require("io-ts/lib/PathReporter"); +const claim_1 = require("./claim"); +const types_1 = require("./types"); +var types_2 = require("./types"); +Object.defineProperty(exports, "ClaimTypes", { enumerable: true, get: function () { return types_2.ClaimTypes; } }); +const MetaType = t.type({ + address: io_1.AddressType, + signature: io_1.SignatureType, +}); +exports.IdentityMetadataType = t.type({ + claims: t.array(claim_1.ClaimType), + meta: MetaType, +}); +class IdentityMetadataWrapper { + static fromEmpty(address) { + return new IdentityMetadataWrapper({ + claims: [], + meta: { + address, + signature: '', + }, + }); + } + static fetchFromURL(contractKitOrAccountsWrapper, url, tries = 3) { + return __awaiter(this, void 0, void 0, function* () { + return (0, async_1.selectiveRetryAsyncWithBackOff)(() => __awaiter(this, void 0, void 0, function* () { + const resp = yield (0, cross_fetch_1.default)(url); + if (!resp.ok) { + throw new Error(`Request failed with status ${resp.status}`); + } + return this.fromRawString(contractKitOrAccountsWrapper, yield resp.text()); + }), tries, ['Request failed with status 404'], []); + }); + } + static fromFile(contractKitOrAccountsWrapper, path) { + let readFileSync; + try { + const fs = require('fs'); + readFileSync = fs.readFileSync; + } + catch (_a) { + console.error('cant read from file in browser or environment without native fs module'); + } + return this.fromRawString(contractKitOrAccountsWrapper, readFileSync(path, 'utf-8')); + } + static verifySigner(contractKitOrAccountsWrapper, hash, signature, metadata) { + return __awaiter(this, void 0, void 0, function* () { + return this.verifySignerForAddress(contractKitOrAccountsWrapper, hash, signature, metadata.address); + }); + } + static verifySignerForAddress(contractKitOrAccountsWrapper, hash, signature, address) { + return __awaiter(this, void 0, void 0, function* () { + // First try to verify on account's address + if (!(0, signatureUtils_1.verifySignature)(hash, signature, address)) { + const accounts = yield getAccounts(contractKitOrAccountsWrapper); + // If this fails, signature may still be one of `address`' signers + if (yield accounts.isAccount(address)) { + const signers = yield Promise.all([ + accounts.getVoteSigner(address), + accounts.getValidatorSigner(address), + accounts.getAttestationSigner(address), + ]); + return signers.some((signer) => (0, signatureUtils_1.verifySignature)(hash, signature, signer)); + } + return false; + } + return true; + }); + } + static fromRawString(contractKitOrAccountsWrapper, rawData) { + return __awaiter(this, void 0, void 0, function* () { + const data = JSON.parse(rawData); + const validatedData = exports.IdentityMetadataType.decode(data); + if ((0, Either_1.isLeft)(validatedData)) { + // TODO: We could probably return a more useful error in the future + throw new Error(PathReporter_1.PathReporter.report(validatedData).join(', ')); + } + // Verify signature on the data + const claims = validatedData.right.claims; + const hash = (0, claim_1.hashOfClaims)(claims); + if (claims.length > 0 && + !(yield this.verifySigner(contractKitOrAccountsWrapper, hash, validatedData.right.meta.signature, validatedData.right.meta))) { + throw new Error(`Signature could not be validated. Guessing signer: ${(0, signatureUtils_1.guessSigner)(hash, validatedData.right.meta.signature)}`); + } + const res = new IdentityMetadataWrapper(validatedData.right); + // Verify that singular claim types appear at most once + types_1.SINGULAR_CLAIM_TYPES.forEach((claimType) => { + const results = res.filterClaims(claimType); + if (results.length > 1) { + throw new Error(`Found ${results.length} claims of type ${claimType}, should be at most 1`); + } + }); + return res; + }); + } + constructor(data) { + this.data = data; + } + get claims() { + return this.data.claims; + } + hashOfClaims() { + return (0, claim_1.hashOfClaims)(this.data.claims); + } + toString() { + return JSON.stringify({ + claims: this.data.claims, + meta: this.data.meta, + }); + } + addClaim(claim, signer) { + return __awaiter(this, void 0, void 0, function* () { + switch (claim.type) { + case types_1.ClaimTypes.ACCOUNT: + if ((0, address_1.eqAddress)(claim.address, this.data.meta.address)) { + throw new Error("Can't claim self"); + } + break; + case types_1.ClaimTypes.DOMAIN: { + const existingClaims = this.data.claims.filter((el) => el.domain === claim.domain); + if (existingClaims.length > 0) { + return existingClaims[0]; + } + break; + } + case types_1.ClaimTypes.KEYBASE: { + const existingClaims = this.data.claims.filter((el) => el.username === claim.username); + if (existingClaims.length > 0) { + return existingClaims[0]; + } + } + default: + break; + } + if (types_1.SINGULAR_CLAIM_TYPES.includes(claim.type)) { + const index = this.data.claims.findIndex((0, claim_1.isOfType)(claim.type)); + if (index !== -1) { + this.data.claims.splice(index, 1); + } + } + this.data.claims.push(claim); + this.data.meta.signature = yield signer.sign(this.hashOfClaims()); + return claim; + }); + } + findClaim(type) { + return this.data.claims.find((0, claim_1.isOfType)(type)); + } + filterClaims(type) { + return this.data.claims.filter((0, claim_1.isOfType)(type)); + } +} +exports.IdentityMetadataWrapper = IdentityMetadataWrapper; +// at first these functions required a `kit` but thats a bit heavy +// as all that is used are functions on the accounts contract so allow just those functions to be passed +function getAccounts(contractKitOrAccountsWrapper) { + return __awaiter(this, void 0, void 0, function* () { + if ('getVoteSigner' in contractKitOrAccountsWrapper && + 'isAccount' in contractKitOrAccountsWrapper && + 'getValidatorSigner' in contractKitOrAccountsWrapper && + 'getAttestationSigner' in contractKitOrAccountsWrapper) { + return contractKitOrAccountsWrapper; + } + throw new Error(`Must pass object with the required functions: getVoteSigner, isAccount, getValidatorSigner, getAttestationSigner. Received ${JSON.stringify(contractKitOrAccountsWrapper)}`); + }); +} +//# sourceMappingURL=metadata.js.map \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/metadata.js.map b/packages/sdk/metadata-claims/lib/metadata.js.map new file mode 100644 index 000000000..8d8b4654a --- /dev/null +++ b/packages/sdk/metadata-claims/lib/metadata.js.map @@ -0,0 +1 @@ +{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA2D;AAC3D,gDAAqE;AAErE,2CAA+D;AAC/D,mEAA6E;AAC7E,8DAA+B;AAC/B,6CAAyC;AACzC,yCAA0B;AAC1B,yDAAqD;AACrD,mCAAgF;AAChF,mCAKgB;AAEhB,iCAAoC;AAA3B,mGAAA,UAAU,OAAA;AAInB,MAAM,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC;IACtB,OAAO,EAAE,gBAAW;IACpB,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,KAAK,CACb,8HAA8H,IAAI,CAAC,SAAS,CAC1I,4BAA4B,CAC7B,EAAE,CACJ,CAAA;IACH,CAAC;CAAA"} \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/types.d.ts b/packages/sdk/metadata-claims/lib/types.d.ts new file mode 100644 index 000000000..d21e1e654 --- /dev/null +++ b/packages/sdk/metadata-claims/lib/types.d.ts @@ -0,0 +1,26 @@ +import * as t from 'io-ts'; +import type { Address, StrongAddress } from '@celo/base/lib/address'; +export declare const SignatureType: t.StringC; +export declare const TimestampType: t.NumberC; +/** @internal */ +export declare const now: () => number; +export declare enum ClaimTypes { + ACCOUNT = "ACCOUNT", + DOMAIN = "DOMAIN", + KEYBASE = "KEYBASE", + NAME = "NAME", + PROFILE_PICTURE = "PROFILE_PICTURE", + STORAGE = "STORAGE", + TWITTER = "TWITTER" +} +export declare const VERIFIABLE_CLAIM_TYPES: ClaimTypes[]; +export declare const SINGULAR_CLAIM_TYPES: ClaimTypes[]; +export type AccountSignerGetters = { + isAccount: (address: Address) => Promise; + getVoteSigner: (address: Address) => Promise; + getValidatorSigner: (address: Address) => Promise; + getAttestationSigner: (address: Address) => Promise; +}; +export type AccountMetadataSignerGetters = { + getMetadataURL: (address: string) => Promise; +} & AccountSignerGetters; diff --git a/packages/sdk/metadata-claims/lib/types.js b/packages/sdk/metadata-claims/lib/types.js new file mode 100644 index 000000000..4058c986c --- /dev/null +++ b/packages/sdk/metadata-claims/lib/types.js @@ -0,0 +1,45 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.SINGULAR_CLAIM_TYPES = exports.VERIFIABLE_CLAIM_TYPES = exports.ClaimTypes = exports.now = exports.TimestampType = exports.SignatureType = void 0; +const t = __importStar(require("io-ts")); +exports.SignatureType = t.string; +exports.TimestampType = t.number; +/** @internal */ +const now = () => Math.round(new Date().getTime() / 1000); +exports.now = now; +var ClaimTypes; +(function (ClaimTypes) { + ClaimTypes["ACCOUNT"] = "ACCOUNT"; + ClaimTypes["DOMAIN"] = "DOMAIN"; + ClaimTypes["KEYBASE"] = "KEYBASE"; + ClaimTypes["NAME"] = "NAME"; + ClaimTypes["PROFILE_PICTURE"] = "PROFILE_PICTURE"; + ClaimTypes["STORAGE"] = "STORAGE"; + ClaimTypes["TWITTER"] = "TWITTER"; +})(ClaimTypes || (exports.ClaimTypes = ClaimTypes = {})); +exports.VERIFIABLE_CLAIM_TYPES = [ClaimTypes.KEYBASE, ClaimTypes.ACCOUNT, ClaimTypes.DOMAIN]; +exports.SINGULAR_CLAIM_TYPES = [ClaimTypes.NAME]; +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/types.js.map b/packages/sdk/metadata-claims/lib/types.js.map new file mode 100644 index 000000000..9deb63c88 --- /dev/null +++ b/packages/sdk/metadata-claims/lib/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA0B;AAIb,QAAA,aAAa,GAAG,CAAC,CAAC,MAAM,CAAA;AACxB,QAAA,aAAa,GAAG,CAAC,CAAC,MAAM,CAAA;AAErC,gBAAgB;AACT,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAA;AAAnD,QAAA,GAAG,OAAgD;AAEhE,IAAY,UAQX;AARD,WAAY,UAAU;IACpB,iCAAmB,CAAA;IACnB,+BAAiB,CAAA;IACjB,iCAAmB,CAAA;IACnB,2BAAa,CAAA;IACb,iDAAmC,CAAA;IACnC,iCAAmB,CAAA;IACnB,iCAAmB,CAAA;AACrB,CAAC,EARW,UAAU,0BAAV,UAAU,QAQrB;AAEY,QAAA,sBAAsB,GAAG,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;AACpF,QAAA,oBAAoB,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA"} \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/verify.d.ts b/packages/sdk/metadata-claims/lib/verify.d.ts new file mode 100644 index 000000000..6a87b4489 --- /dev/null +++ b/packages/sdk/metadata-claims/lib/verify.d.ts @@ -0,0 +1,20 @@ +/// +import { AccountClaim } from './account'; +import { Claim, DomainClaim } from './claim'; +import { AccountMetadataSignerGetters } from './types'; +/** + * Verifies a claim made by an account, i.e. whether a claim can be verified to be correct + * @param kit AccountMetadataSignerGetters object + * @param claim The claim to verify + * @param address The address that is making the claim + * @returns If valid, returns undefined. If invalid or unable to verify, returns a string with the error + */ +export declare function verifyClaim(accountMeta: AccountMetadataSignerGetters, claim: Claim, address: string, tries?: number): Promise; +export declare const verifyAccountClaim: (accountMeta: AccountMetadataSignerGetters, claim: AccountClaim, address: string, tries?: number) => Promise; +type dnsResolverFunction = (hostname: string, callback: (err: NodeJS.ErrnoException, addresses: string[][]) => void) => void; +/** + * It verifies if a DNS domain includes in the TXT records an entry with name + * `celo-site-verification` and a valid signature in base64 + */ +export declare const verifyDomainRecord: (accountMeta: AccountMetadataSignerGetters, claim: DomainClaim, address: string, dnsResolver?: dnsResolverFunction) => Promise; +export {}; diff --git a/packages/sdk/metadata-claims/lib/verify.js b/packages/sdk/metadata-claims/lib/verify.js new file mode 100644 index 000000000..0b8fa8f1f --- /dev/null +++ b/packages/sdk/metadata-claims/lib/verify.js @@ -0,0 +1,89 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.verifyDomainRecord = exports.verifyAccountClaim = exports.verifyClaim = void 0; +const address_1 = require("@celo/base/lib/address"); +const io_1 = require("@celo/base/lib/io"); +const node_dns_1 = require("node:dns"); // TODO replace with non node specifc package +const node_util_1 = require("node:util"); // TODO replace with non node specifc package +const claim_1 = require("./claim"); +const keybase_1 = require("./keybase"); +const metadata_1 = require("./metadata"); +const types_1 = require("./types"); +/** + * Verifies a claim made by an account, i.e. whether a claim can be verified to be correct + * @param kit AccountMetadataSignerGetters object + * @param claim The claim to verify + * @param address The address that is making the claim + * @returns If valid, returns undefined. If invalid or unable to verify, returns a string with the error + */ +function verifyClaim(accountMeta, claim, address, tries = 3) { + return __awaiter(this, void 0, void 0, function* () { + switch (claim.type) { + case types_1.ClaimTypes.KEYBASE: + return (0, keybase_1.verifyKeybaseClaim)(accountMeta, claim, address); + case types_1.ClaimTypes.ACCOUNT: + return (0, exports.verifyAccountClaim)(accountMeta, claim, address, tries); + case types_1.ClaimTypes.DOMAIN: + return (0, exports.verifyDomainRecord)(accountMeta, claim, address); + default: + break; + } + return; + }); +} +exports.verifyClaim = verifyClaim; +const verifyAccountClaim = (accountMeta, claim, address, tries = 3) => __awaiter(void 0, void 0, void 0, function* () { + const metadataURL = yield accountMeta.getMetadataURL(claim.address); + if (!(0, io_1.isValidUrl)(metadataURL)) { + return `Metadata URL of ${claim.address} could not be retrieved`; + } + let metadata; + try { + metadata = yield metadata_1.IdentityMetadataWrapper.fetchFromURL(accountMeta, metadataURL, tries); + } + catch (error) { + return `Metadata could not be fetched for ${claim.address} at ${metadataURL}: ${error.toString()}`; + } + const accountClaims = metadata.filterClaims(types_1.ClaimTypes.ACCOUNT); + if (accountClaims.find((x) => (0, address_1.eqAddress)(x.address, address)) === undefined) { + return `${claim.address} did not claim ${address}`; + } + return; +}); +exports.verifyAccountClaim = verifyAccountClaim; +/** + * It verifies if a DNS domain includes in the TXT records an entry with name + * `celo-site-verification` and a valid signature in base64 + */ +const verifyDomainRecord = (accountMeta, claim, address, dnsResolver = node_dns_1.resolveTxt) => __awaiter(void 0, void 0, void 0, function* () { + try { + const getRecords = (0, node_util_1.promisify)(dnsResolver); + const domainRecords = yield getRecords(claim.domain); + for (const record of domainRecords) { + for (const entry of record) { + if (entry.startsWith(claim_1.DOMAIN_TXT_HEADER)) { + const signatureBase64 = entry.substring(claim_1.DOMAIN_TXT_HEADER.length + 1); + const signature = Buffer.from(signatureBase64, 'base64').toString('binary'); + if (yield metadata_1.IdentityMetadataWrapper.verifySignerForAddress(accountMeta, (0, claim_1.serializeClaim)(claim), signature, address)) { + return; + } + } + } + } + return `Unable to verify domain claim with address ${address}`; + } + catch (error) { + return `Unable to fetch domain TXT records: ${error.toString()}`; + } +}); +exports.verifyDomainRecord = verifyDomainRecord; +//# sourceMappingURL=verify.js.map \ No newline at end of file diff --git a/packages/sdk/metadata-claims/lib/verify.js.map b/packages/sdk/metadata-claims/lib/verify.js.map new file mode 100644 index 000000000..5f301444a --- /dev/null +++ b/packages/sdk/metadata-claims/lib/verify.js.map @@ -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ACrB,SAAS,EACT,OAAO,CACR,EACD,CAAC;wBACD,OAAM;oBACR,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,8CAA8C,OAAO,EAAE,CAAA;IAChE,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,OAAO,uCAAuC,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAA;IAClE,CAAC;AACH,CAAC,CAAA,CAAA;AA/BY,QAAA,kBAAkB,sBA+B9B"} \ No newline at end of file diff --git a/packages/sdk/utils/src/contacts.ts b/packages/sdk/utils/src/contacts.ts deleted file mode 100644 index c5b85baba..000000000 --- a/packages/sdk/utils/src/contacts.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { MinimalContact } from '@celo/base/lib/contacts' -import { keccak256 } from 'web3-utils' - -// Exports moved to @celo/base, forwarding them -// here for backwards compatibility -export { - ContactPhoneNumber, - getContactPhoneNumber, - isContact, - MinimalContact, -} from '@celo/base/lib/contacts' - -/** - * @deprecated May be removed in future - */ -export const getContactNameHash = (contact: MinimalContact) => { - if (!contact) { - throw new Error('Invalid contact') - } - - return keccak256(contact.displayName || '') -} diff --git a/packages/sdk/utils/src/currencies.ts b/packages/sdk/utils/src/currencies.ts deleted file mode 100644 index eaba79f5e..000000000 --- a/packages/sdk/utils/src/currencies.ts +++ /dev/null @@ -1,9 +0,0 @@ -// Exports moved to @celo/base, forwarding them -// here for backwards compatibility -export { - CURRENCIES, - currencyToShortMap, - CURRENCY_ENUM, - resolveCurrency, - SHORT_CURRENCIES, -} from '@celo/base/lib/currencies' diff --git a/packages/sdk/utils/src/displayFormatting.ts b/packages/sdk/utils/src/displayFormatting.ts deleted file mode 100644 index 9b612e3cc..000000000 --- a/packages/sdk/utils/src/displayFormatting.ts +++ /dev/null @@ -1,3 +0,0 @@ -// Exports moved to @celo/base, forwarding them -// here for backwards compatibility -export { getErrorMessage } from '@celo/base/lib/displayFormatting' diff --git a/packages/sdk/utils/src/index.ts b/packages/sdk/utils/src/index.ts index f1699972c..ad903fba4 100644 --- a/packages/sdk/utils/src/index.ts +++ b/packages/sdk/utils/src/index.ts @@ -1,7 +1,4 @@ import * as AddressUtils from './address' - -export * from './contacts' -export * from './currencies' export { ECIES } from './ecies' export { IstanbulUtils } from './istanbul' export { SignatureUtils } from './signatureUtils'