Skip to content

Commit cf69aa9

Browse files
Merge pull request #53 from Bako-Labs/p2/feat/add-prefix-to-social-address
FEAT: add prefix to social address
2 parents e15b090 + 6c61e46 commit cf69aa9

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed

.changeset/flat-forks-protect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'bakosafe': patch
3+
---
4+
5+
Address can be formatted with the prefix `social`

packages/sdk/src/modules/address/Address.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,25 @@ export class AddressUtils {
1616
return value.startsWith(Bech32Prefix.PASSKEY);
1717
}
1818

19+
static isSocial(value: string): boolean {
20+
return value.startsWith(Bech32Prefix.SOCIAL);
21+
}
22+
1923
/**
20-
* @deprecated Use toPasskey instead
24+
* Converts a hex address to Bech32 prefix format
25+
* @param address - The hex address to convert
26+
* @param prefix - The Bech32 prefix to use
27+
* @returns The Bech32 address with the specified prefix
2128
*/
22-
static toBech32 = (address: string) =>
23-
<Bech32>(
24-
bech32m.encode(
25-
Bech32Prefix.PASSKEY,
26-
bech32m.toWords(arrayify(hexlify(address))),
27-
)
28-
);
29+
static toBech32 = (address: string, prefix: Bech32Prefix) =>
30+
<Bech32>bech32m.encode(prefix, bech32m.toWords(arrayify(hexlify(address))));
2931

3032
/**
3133
* Converts a hex address to Bech32 passkey format
3234
* @param address - The hex address to convert
3335
* @returns The Bech32 passkey address
36+
*
37+
* @deprecated Use toBech32 instead
3438
*/
3539
static toPasskey = (address: string) =>
3640
<Bech32>(

packages/sdk/src/modules/address/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,18 @@ Converts an array of hex addresses to string representation, filtering out ZeroB
3232

3333
Checks if an address is a passkey address by verifying if it starts with the passkey prefix.
3434

35-
### toBech32(address: string): Bech32
35+
### isSocial(value: string): boolean
3636

37-
**@deprecated** Use `toPasskey` instead.
37+
Checks if an address is a social address by verifying if it starts with the social prefix.
3838

39-
Converts a hex address to Bech32 passkey format.
39+
### toBech32(address: string, prefix: Bech32Prefix): Bech32
40+
41+
Converts a hex address to Bech32 prefix format.
4042

4143
### toPasskey(address: string): Bech32
4244

45+
**@deprecated** Use `toBech32` instead.
46+
4347
Converts a hex address to Bech32 passkey format.
4448

4549
### fromBech32(address: Bech32): string
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export enum Bech32Prefix {
22
PASSKEY = 'passkey',
3+
SOCIAL = 'social',
34
}
45

56
export type Bech32 = `${Bech32Prefix}.${string}`;
6-

packages/tests/src/configurable.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Vault, ConfigVaultType, AddressUtils } from 'bakosafe';
1+
import { Vault, ConfigVaultType, AddressUtils, Bech32Prefix } from 'bakosafe';
22
import { Address, Provider, ZeroBytes32 } from 'fuels';
33
import { launchTestNode } from 'fuels/test-utils';
44
import { accounts } from './mocks';
@@ -137,7 +137,10 @@ describe('[Configurable Functions]', () => {
137137
it('should create vault for compatible version webauthn_wallet:evm_connector_version', () => {
138138
const webauthn_wallet = WebAuthn.createCredentials();
139139
const connectorConfig = {
140-
SIGNER: AddressUtils.toPasskey(webauthn_wallet.address),
140+
SIGNER: AddressUtils.toBech32(
141+
webauthn_wallet.address,
142+
Bech32Prefix.PASSKEY,
143+
),
141144
};
142145

143146
expect(() => {

0 commit comments

Comments
 (0)