Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
Metamask Snap
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
Metamask Snap
Commits
2725f3eb
Verified
Commit
2725f3eb
authored
1 week ago
by
Mateusz Tyszczak
Browse files
Options
Downloads
Patches
Plain Diff
Use BIP44 entropy instead of BIP32
parent
0cd657e3
No related branches found
No related tags found
No related merge requests found
Pipeline
#118995
passed
1 week ago
Stage: build
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
package.json
+1
-1
1 addition, 1 deletion
package.json
snap.manifest.json
+4
-11
4 additions, 11 deletions
snap.manifest.json
src/utils/key-management.ts
+20
-23
20 additions, 23 deletions
src/utils/key-management.ts
with
25 additions
and
35 deletions
package.json
+
1
−
1
View file @
2725f3eb
{
{
"name"
:
"@hiveio/metamask-snap"
,
"name"
:
"@hiveio/metamask-snap"
,
"version"
:
"1.
3.3
"
,
"version"
:
"1.
4.0
"
,
"description"
:
"Hive wallet extension allowing you to sign transactions using keys derived from your Metamask wallet"
,
"description"
:
"Hive wallet extension allowing you to sign transactions using keys derived from your Metamask wallet"
,
"main"
:
"./dist/bundle.js"
,
"main"
:
"./dist/bundle.js"
,
"files"
:
[
"files"
:
[
...
...
This diff is collapsed.
Click to expand it.
snap.manifest.json
+
4
−
11
View file @
2725f3eb
{
{
"version"
:
"1.
3.3
"
,
"version"
:
"1.
4.0
"
,
"description"
:
"Hive wallet extension allowing you to sign transactions using keys derived from your Metamask wallet"
,
"description"
:
"Hive wallet extension allowing you to sign transactions using keys derived from your Metamask wallet"
,
"proposedName"
:
"Hive Wallet"
,
"proposedName"
:
"Hive Wallet"
,
"repository"
:
{
"repository"
:
{
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
"url"
:
"git+https://gitlab.syncad.com/hive/metamask-snap.git"
"url"
:
"git+https://gitlab.syncad.com/hive/metamask-snap.git"
},
},
"source"
:
{
"source"
:
{
"shasum"
:
"
O7LMRoprQOJvI9FF1oXBJX0UdRamQM8jXstqhRspMUQ
="
,
"shasum"
:
"
QnK+W9d9Xy2Iv5TIZRhULm6OdccrCPxDGiRtY7kZtcU
="
,
"location"
:
{
"location"
:
{
"npm"
:
{
"npm"
:
{
"filePath"
:
"dist/bundle.js"
,
"filePath"
:
"dist/bundle.js"
,
...
@@ -24,16 +24,9 @@
...
@@ -24,16 +24,9 @@
"snaps"
:
false
"snaps"
:
false
},
},
"endowment:webassembly"
:
{},
"endowment:webassembly"
:
{},
"snap_getBip
32
Entropy"
:
[
"snap_getBip
44
Entropy"
:
[
{
{
"path"
:
[
"m"
,
"48'"
,
"13'"
],
"coinType"
:
3054
"curve"
:
"secp256k1"
}
],
"snap_getBip32PublicKey"
:
[
{
"path"
:
[
"m"
,
"48'"
,
"13'"
],
"curve"
:
"secp256k1"
}
}
]
]
},
},
...
...
This diff is collapsed.
Click to expand it.
src/utils/key-management.ts
+
20
−
23
View file @
2725f3eb
...
@@ -2,7 +2,7 @@ import type { TPublicKey, TRole } from "@hiveio/wax";
...
@@ -2,7 +2,7 @@ import type { TPublicKey, TRole } from "@hiveio/wax";
import
type
{
KeyIndex
}
from
"
../rpc
"
;
import
type
{
KeyIndex
}
from
"
../rpc
"
;
import
{
getWax
}
from
"
../hive/wax
"
;
import
{
getWax
}
from
"
../hive/wax
"
;
import
{
remove0x
}
from
"
@metamask/utils
"
;
import
{
remove0x
}
from
"
@metamask/utils
"
;
import
{
SLIP10Node
}
from
"
@metamask/key-tree
"
;
import
{
type
BIP44Node
,
getBIP44AddressKeyDeriver
}
from
"
@metamask/key-tree
"
;
import
type
{
IBeekeeperUnlockedWallet
}
from
"
@hiveio/beekeeper
"
;
import
type
{
IBeekeeperUnlockedWallet
}
from
"
@hiveio/beekeeper
"
;
const
KeyIndexToPathMap
=
{
const
KeyIndexToPathMap
=
{
...
@@ -12,27 +12,32 @@ const KeyIndexToPathMap = {
...
@@ -12,27 +12,32 @@ const KeyIndexToPathMap = {
posting
:
4
posting
:
4
}
as const
satisfies
Record
<
TRole
,
number
>
;
}
as const
satisfies
Record
<
TRole
,
number
>
;
export
const
keyIndexToPath
=
(
keyIndex
:
KeyIndex
):
string
[]
=>
{
const
CoinType
=
0xBEE
;
export
const
keyIndexToBip44Node
=
async
(
keyIndex
:
KeyIndex
):
Promise
<
BIP44Node
>
=>
{
const
bip44
=
await
snap
.
request
({
method
:
'
snap_getBip44Entropy
'
,
params
:
{
coinType
:
CoinType
}
});
// Create a function that takes an index and returns an extended private key for m/44'/3054'/accountIndex'/0/address_index
const
deriveHiveAddress
=
await
getBIP44AddressKeyDeriver
(
bip44
,
{
account
:
keyIndex
.
accountIndex
??
0
,
change
:
0
});
const
keyIndexType
=
KeyIndexToPathMap
[
keyIndex
.
role
];
const
keyIndexType
=
KeyIndexToPathMap
[
keyIndex
.
role
];
if
(
keyIndexType
===
undefined
)
if
(
keyIndexType
===
undefined
)
throw
new
Error
(
`Invalid key index type:
${
keyIndex
.
role
}
`
);
throw
new
Error
(
`Invalid key index type:
${
keyIndex
.
role
}
`
);
return
[
"
m
"
,
"
48'
"
,
"
13'
"
,
`
${
keyIndexType
}
'`
,
`
${
keyIndex
.
accountIndex
??
0
}
'`
,
"
0'
"
];
// Derive the second Hive address, which has a proper index.
return
await
deriveHiveAddress
(
keyIndexType
);
};
};
export
const
getPublicKeyWifFromKeyIndex
=
async
(
keyIndex
:
KeyIndex
):
Promise
<
TPublicKey
>
=>
{
export
const
getPublicKeyWifFromKeyIndex
=
async
(
keyIndex
:
KeyIndex
):
Promise
<
TPublicKey
>
=>
{
const
wax
=
await
getWax
();
const
wax
=
await
getWax
();
const
bip32
=
await
snap
.
request
({
const
bip44Node
=
await
keyIndexToBip44Node
(
keyIndex
);
method
:
'
snap_getBip32PublicKey
'
,
params
:
{
curve
:
"
secp256k1
"
,
path
:
keyIndexToPath
(
keyIndex
),
compressed
:
true
}
});
const
publicKey
=
wax
.
convertRawPublicKeyToWif
(
remove0x
(
bip
32
));
const
publicKey
=
wax
.
convertRawPublicKeyToWif
(
remove0x
(
bip
44Node
.
compressedPublicKey
));
return
publicKey
;
return
publicKey
;
};
};
...
@@ -40,20 +45,12 @@ export const getPublicKeyWifFromKeyIndex = async (keyIndex: KeyIndex): Promise<T
...
@@ -40,20 +45,12 @@ export const getPublicKeyWifFromKeyIndex = async (keyIndex: KeyIndex): Promise<T
export
const
getPrivateKeyWifFromKeyIndex
=
async
(
keyIndex
:
KeyIndex
):
Promise
<
string
>
=>
{
export
const
getPrivateKeyWifFromKeyIndex
=
async
(
keyIndex
:
KeyIndex
):
Promise
<
string
>
=>
{
const
wax
=
await
getWax
();
const
wax
=
await
getWax
();
const
snapResponse
=
await
snap
.
request
({
const
bip44Node
=
await
keyIndexToBip44Node
(
keyIndex
);
method
:
'
snap_getBip32Entropy
'
,
params
:
{
curve
:
"
secp256k1
"
,
path
:
keyIndexToPath
(
keyIndex
)
}
});
const
node
=
await
SLIP10Node
.
fromJSON
(
snapResponse
);
if
(
!
n
ode
.
privateKey
)
if
(
!
bip44N
ode
.
privateKey
)
throw
new
Error
(
'
No private key found
'
);
throw
new
Error
(
'
No private key found
'
);
const
wif
=
wax
.
convertRawPrivateKeyToWif
(
remove0x
(
n
ode
.
privateKey
));
const
wif
=
wax
.
convertRawPrivateKeyToWif
(
remove0x
(
bip44N
ode
.
privateKey
));
return
wif
;
return
wif
;
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment